UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#212635#3835. 数列变换one_zero_four_zero200ms1208kbC++11981b2024-10-19 17:37:122024-10-19 18:37:12

answer

#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

int N, M, Q;
int l, r;
long long v, a[500005], b[500005];

void update(int l, int r, long long cur){
	for (int i = l; i <= r; i ++){
		a[i] += cur;
	}
}

long long solve(){
	long long res = 0;
	for (int k = 0; k <= M - N; k ++){
		long long tmp = 0, pow = 0;
		for (int i = 1; i <= N; i ++){
			pow = ((i & 1) ? 1 : -1);
			tmp += pow * (a[i] - b[i + k]);
		}
		if (!k) res = abs(tmp);
		res = min(res, abs(tmp));
	}
	return res;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("data.in", "r", stdin);
	freopen("data.out", "w", stdout);
#endif

	scanf("%d %d %d", &N, &M, &Q);
	for (int i = 1; i <= N; i ++){
		scanf("%lld", &a[i]);
	}
	for (int i = 1; i <= M; i ++){
		scanf("%lld", &b[i]);
	}
	printf("%lld\n", solve());
	while (Q --){
		scanf("%d %d %lld", &l, &r, &v);
		if (l > r) swap(l, r);
		update(l, r, v);
		printf("%lld\n", solve());
	}

	return 0;
}

Details

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

Test #1:

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

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: 0ms
memory: 1200kb

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: 0
Time Limit Exceeded

input:

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

output:


result:


Test #4:

score: 0
Time Limit Exceeded

input:

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

output:


result:


Test #5:

score: 0
Time Limit Exceeded

input:

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

output:


result:


Test #6:

score: 0
Time Limit Exceeded

input:

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

output:


result:


Test #7:

score: 0
Time Limit Exceeded

input:

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

output:


result:


Test #8:

score: 0
Time Limit Exceeded

input:

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

output:


result:


Test #9:

score: 0
Time Limit Exceeded

input:

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

output:


result:


Test #10:

score: 0
Time Limit Exceeded

input:

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

output:


result: