UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202990#2618. 内积snow_trace1001193ms5576kbC++111.5kb2024-02-18 10:42:222024-02-18 13:23:43

answer

#include<bits/stdc++.h>
using namespace std;
const long long inf = 3000000000000000000;
vector<pair<int,int> >p[100005];
int n,q;
long long x[100005],y[100005];
bool vis[100005];
long long ans = -inf;
long long X,Y;vector<int>vv;
int fa[100005];
int find(int x){
	if(fa[x] == x)return x;return fa[x] = find(fa[x]);
}void merge(int x,int y){fa[find(x)] = find(y);}int id;
inline void dfs(int now){
	vv.push_back(now);vis[now] = 1;
	ans = max(ans,X*x[now]+Y*y[now]);
	for(int i =0;i<p[now].size();i++){
		if(vis[p[now][i].first] or p[now][i].second>=id)continue;
		dfs(p[now][i].first);
	}
}
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >>n>>q;
	for(int i = 1;i<=n;i++)cin>>x[i];
	for(int i = 1;i<=n;i++)cin>>y[i];
	for(int i = 1;i<=n;i++)fa[i] = i;
	long long lastans = 0;
	for(int i = 1;i<=q;i++){
		int op;cin>>op;
		if(op == 0){
			long long u,v,s;cin>>u>>v>>s;
			u = (u+s*lastans)%n+1,v = (v+s*lastans)%n+1;
			if(find(u) == find(v))continue;merge(u,v);
			p[u].push_back({v,i}),p[v].push_back({u,i});
		}else{long long u,s;
			cin>>X>>Y>>u>>id>>s;
			u = (u+s*lastans)%n+1,id = (id+s*lastans)%i+1;
			vv.clear();ans = -inf;dfs(u);cout<<(lastans = ans)<<'\n';
			if(ans<0)lastans*=-1;
			for(int x:vv)vis[x] = 0;
		}
	}
	return 0;
}
/*
我肯定会 polylog 做法,能不能比 n2 快另说。
显然这个东西可以用李超树做,但是需要实现的东西是可持久化李超树合并加上可持久化并查集。
这我哪会啊?
*/

这程序好像有点Bug,我给组数据试试?

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 5
Accepted
time: 0ms
memory: 3660kb

input:

1000 1000
-421419446 -136785968 -345521518 -100976830 -679011683 -99575514 52479961 997866866 -31124...

output:

-611374127803052404
-446180822106604074
-812015101235480996
-393099200702410958
116460557006253348
-...

result:

ok 516 numbers

Test #2:

score: 5
Accepted
time: 53ms
memory: 5572kb

input:

100000 100000
7 10 -1 8 -2 6 -5 -1 10 -6 0 -4 9 10 4 -4 6 5 9 -3 0 2 9 -4 0 10 -10 -2 -10 -5 1 -8 9 ...

output:

70
-28
-21
61
-28
-42
-70
-63
45
-63
-28
-56
0
92
11
72
14
-63
-7
74
-63
80
-70
31
93
7
88
48
-42
-6...

result:

ok 50074 numbers

Test #3:

score: 5
Accepted
time: 54ms
memory: 5572kb

input:

100000 100000
7 -6 -9 7 -7 -1 6 -5 4 1 -4 -2 -4 8 0 9 4 -2 -7 1 -1 6 6 8 -1 10 5 -1 1 5 5 7 -6 -3 2 ...

output:

-7
13
78
13
53
-5
51
39
51
57
17
43
51
54
48
28
8
67
33
42
40
-10
18
5
52
56
30
33
35
21
29
14
35
31...

result:

ok 50058 numbers

Test #4:

score: 5
Accepted
time: 51ms
memory: 5572kb

input:

100000 100000
-9 1 6 -4 10 3 3 -1 6 2 -6 -5 -2 -7 8 -9 4 7 7 7 10 10 9 0 10 3 0 -3 10 9 10 6 -3 -1 1...

output:

-2
72
-134
-36
8
-79
108
-125
122
84
1
-2
23
9
-1
26
-1
11
89
73
97
4
80
45
53
0
97
5
-12
13
1
4
-5
...

result:

ok 50070 numbers

Test #5:

score: 5
Accepted
time: 56ms
memory: 5576kb

input:

100000 100000
-1 1 -1 -5 0 -8 10 -5 0 -9 -9 -2 5 8 8 0 -6 4 8 2 -8 10 -3 0 5 6 -5 2 -8 -7 10 4 3 6 5...

output:

1
7
-7
3
-1
5
14
3
7
5
7
10
12
14
1
10
3
6
1
8
17
10
7
1
5
0
9
-2
5
3
-2
6
4
1
4
-2
15
7
3
3
5
-1
12...

result:

ok 50028 numbers

Test #6:

score: 5
Accepted
time: 66ms
memory: 5572kb

input:

100000 100000
-421419446 -136785968 -345521518 -100976830 -679011683 -99575514 52479961 997866866 -3...

output:

99131640045164728
-149759853458626063
426839912997104511
-5164961399566911
-121061024365292005
-2829...

result:

ok 50074 numbers

Test #7:

score: 5
Accepted
time: 68ms
memory: 5572kb

input:

100000 100000
105942958 -787187628 -957648699 -827582912 339376616 -135566197 509551371 -137901269 -...

output:

551706261482336936
-430066504696147646
236423930126650929
-315219791923600673
257608959793035483
627...

result:

ok 50058 numbers

Test #8:

score: 5
Accepted
time: 73ms
memory: 5572kb

input:

100000 100000
-656013429 817172557 635643051 -57830080 937366927 267373146 -618573066 -973686658 462...

output:

-925375081306167401
-613541888239927530
-1094892680105410871
-534453011856843900
-716902042429212448...

result:

ok 50070 numbers

Test #9:

score: 5
Accepted
time: 69ms
memory: 5576kb

input:

100000 100000
461283563 218648398 23515871 -784436162 7632726 -63584831 -456468950 -109454792 223340...

output:

-315255593600942732
-121733177343637748
-230037286777663234
-237566038926004515
-80149033918745929
-...

result:

ok 50028 numbers

Test #10:

score: 5
Accepted
time: 59ms
memory: 5576kb

input:

100000 100000
-837133362 146509274 -12883362 645754049 -206736193 -448453 -310446691 454794328 -1027...

output:

-32671473289666608
-884016921163079032
1233805710265940354
1261408686141504030
306226680962288593
89...

result:

ok 50040 numbers

Test #11:

score: 5
Accepted
time: 58ms
memory: 5576kb

input:

100000 100000
-421419446 -136785968 -345521518 -100976830 -679011683 -99575514 52479961 997866866 -3...

output:

459247705483080049
-139245311044598704
-262322249219244852
-480808100050890760
-260612948767620958
6...

result:

ok 50000 numbers

Test #12:

score: 5
Accepted
time: 63ms
memory: 5576kb

input:

100000 100000
105942958 -787187628 -957648699 -827582912 339376616 -135566197 509551371 -137901269 -...

output:

686877167096018988
169989719560303264
-283773733056574613
236423930126650929
-265368081881614643
622...

result:

ok 50000 numbers

Test #13:

score: 5
Accepted
time: 75ms
memory: 5572kb

input:

100000 100000
-656013429 817172557 635643051 -57830080 937366927 267373146 -618573066 -973686658 462...

output:

281097473884961131
222631744708812031
294659937244366814
262784146400421264
770459328981529046
16887...

result:

ok 50000 numbers

Test #14:

score: 5
Accepted
time: 61ms
memory: 5572kb

input:

100000 100000
461283563 218648398 23515871 -784436162 7632726 -63584831 -456468950 -109454792 223340...

output:

130657339400270761
231079164936643056
-185032905953660346
-174664572412787984
190744097763016846
-25...

result:

ok 50000 numbers

Test #15:

score: 5
Accepted
time: 62ms
memory: 5576kb

input:

100000 100000
-837133362 146509274 -12883362 645754049 -206736193 -448453 -310446691 454794328 -1027...

output:

-38891255578685794
26869229524821300
509933423574233828
-262168843427855409
488962398682122628
12614...

result:

ok 50000 numbers

Test #16:

score: 5
Accepted
time: 69ms
memory: 5576kb

input:

100000 100000
-421419446 -136785968 -345521518 -100976830 -679011683 -99575514 52479961 997866866 -3...

output:

99131640045164728
-149759853458626063
426839912997104511
-5164961399566911
-121061024365292005
-2829...

result:

ok 50074 numbers

Test #17:

score: 5
Accepted
time: 67ms
memory: 5572kb

input:

100000 100000
105942958 -787187628 -957648699 -827582912 339376616 -135566197 509551371 -137901269 -...

output:

551706261482336936
-430066504696147646
236423930126650929
-315219791923600673
257608959793035483
627...

result:

ok 50058 numbers

Test #18:

score: 5
Accepted
time: 71ms
memory: 5572kb

input:

100000 100000
-656013429 817172557 635643051 -57830080 937366927 267373146 -618573066 -973686658 462...

output:

-925375081306167401
-613541888239927530
-1094892680105410871
-534453011856843900
-716902042429212448...

result:

ok 50070 numbers

Test #19:

score: 5
Accepted
time: 50ms
memory: 5576kb

input:

100000 100000
461283563 218648398 23515871 -784436162 7632726 -63584831 -456468950 -109454792 223340...

output:

-315255593600942732
-121733177343637748
-230037286777663234
-237566038926004515
-80149033918745929
-...

result:

ok 50028 numbers

Test #20:

score: 5
Accepted
time: 68ms
memory: 5572kb

input:

100000 100000
-837133362 146509274 -12883362 645754049 -206736193 -448453 -310446691 454794328 -1027...

output:

-32671473289666608
-884016921163079032
1233805710265940354
1261408686141504030
306226680962288593
89...

result:

ok 50040 numbers