UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#212626#3835. 数列变换drdilyor100569ms8996kbC++1.3kb2024-10-19 14:53:422024-10-19 18:36:20

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
void ts(){cout<<"IAKIOI\n";}
inline int read(){
	int n=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		n=n*10+ch-'0';
		ch=getchar();
	}
	return n*f;
}
int n,m,q;
int a[500005],b[500005];
int f[500005];
signed main(){
	n=read(),m=read(),q=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1;i<=m;i++)b[i]=read();
	int sa=0;
	for(int i=1;i<=n;i++){
		if(i&1)sa+=a[i];
		else sa-=a[i];
	}
	for(int i=1;i<=n;i++){
		if(i&1)f[0]-=b[i];
		else f[0]+=b[i];
	}
	for(int i=1;i<=m-n;i++){
		f[i]=f[i-1]+b[i];
		f[i]=-f[i];
		if(n&1)f[i]-=b[i+n];
		else f[i]+=b[i+n];
	}
	sort(f,f+m-n+1);
	int res=1ll<<60;
	for(int i=0;i<=m-n;i++)res=min(res,abs(sa+f[i]));
	cout<<res<<"\n";
	while(q--){
		int l=read(),r=read(),v=read();
		if(l>r)swap(l,r);
		int o=0;
		int ql=l,qr=r;
		if(ql%2==0)ql++;
		if(qr%2==0)qr--;
		if(ql<=qr)o=(qr-ql)/2+1;
		int e=r-l+1-o;
		sa+=(o-e)*v;
		//cout<<sa<<" ";
		//sa+f[i]<=0 最大的 f[i]
		int vv=lower_bound(f,f+m-n+1,-sa)-f;
		res=1ll<<60;
		for(int i=max(vv-5,0ll);i<=min(m-n,vv+5);i++)res=min(res,abs(sa+f[i]));
		cout<<res<<"\n";
	}
	//15 3 7
	return 0;
}
//look at my code
//my code is amazing

Details

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

Test #1:

score: 10
Accepted
time: 0ms
memory: 1188kb

input:

60 100 100
-316328 -2972020 4147918 -2643712 5196821 -5222175 1264902 8662970 -2730531 -8400380 1752...

output:

455979
455979
455979
455979
455979
455979
455979
455978
455972
455965
455965
455966
455968
455968
45...

result:

ok 101 numbers

Test #2:

score: 10
Accepted
time: 1ms
memory: 1184kb

input:

60 100 100
-91495081 53528918 88188311 -74258245 -66799442 -49965187 -7645181 -44417344 -39124339 58...

output:

8190568
8190568
2233401
7193707
4795408
4795408
4795408
1179783
1179783
11716793
11716793
1174744
12...

result:

ok 101 numbers

Test #3:

score: 10
Accepted
time: 2ms
memory: 1224kb

input:

1000 2500 5000
-98154920 -53785940 -74265506 3679870 37683369 24917745 -92422231 8884275 -81169328 9...

output:

107041
107041
107041
107041
107041
797385
791567
791567
1392939
1392939
1392939
961800
819544
819544...

result:

ok 5001 numbers

Test #4:

score: 10
Accepted
time: 1ms
memory: 1248kb

input:

2500 4000 5000
-86828824 -50617376 6649487 69943467 -93306697 -6567886 -95650455 -85852213 -15523487...

output:

573304251
573304251
595203952
694987953
680315084
728371583
782122701
782122701
825849022
915038502
...

result:

ok 5001 numbers

Test #5:

score: 10
Accepted
time: 1ms
memory: 1268kb

input:

3000 5000 5000
-80381922 79980974 3347134 -52177075 -66392451 -488143 4131024 -16842638 -12729315 27...

output:

5066626
3060888
6135718
46352
94807
94807
165432
448427
448427
55386
627630
627630
594397
39417
2439...

result:

ok 5001 numbers

Test #6:

score: 10
Accepted
time: 75ms
memory: 3524kb

input:

50000 150000 150000
-89108065 59343099 -97978207 -67393513 -61842201 75668265 80917778 -98775029 -68...

output:

367594
148610
759512
244446
136839
83073
302547
215766
162990
40016
136848
422047
89049
98658
343712...

result:

ok 150001 numbers

Test #7:

score: 10
Accepted
time: 82ms
memory: 3524kb

input:

100000 150000 150000
-90110621 -17018593 7329896 -25804788 -19546767 -52028202 -97290926 -68550106 7...

output:

9264157442
9362400005
9287250254
9368053211
9411500623
9385277837
9435812025
9436874552
9380121876
9...

result:

ok 150001 numbers

Test #8:

score: 10
Accepted
time: 67ms
memory: 2748kb

input:

50000 100000 150000
-99258224 -12730699 -92233936 -33566265 -39312752 -10318733 -19880407 69141095 -...

output:

128989
103327
95283
173047
317772
307164
307164
9121
9121
69178
244
144419
144419
190182
190182
2618...

result:

ok 150001 numbers

Test #9:

score: 10
Accepted
time: 99ms
memory: 3528kb

input:

80000 150000 150000
-75009884 -81911105 -96479382 73988847 18413858 58416050 60800947 -59117071 -596...

output:

343226
343226
382382
236941
997
997
997
997
997
997
997
166301
506372
488607
506128
506128
117946
13...

result:

ok 150001 numbers

Test #10:

score: 10
Accepted
time: 241ms
memory: 8996kb

input:

263999 500000 500000
-7398172 -81831034 99536754 -91618991 31225194 -18967333 -15490068 31299796 -52...

output:

447372176
412567992
370536501
370536501
370536501
370536501
432667527
432667527
411201828
411201828
...

result:

ok 500001 numbers

Extra Test:

score: 0
Extra Test Passed