Submission #967307

# Submission time Handle Problem Language Result Execution time Memory
967307 2024-04-21T19:55:06 Z Math4Life2020 Sjeckanje (COCI21_sjeckanje) C++17
0 / 110
1 ms 348 KB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;

int main() {
	long long N,Q; cin >> N >> Q;
	long long a[N];
	for (long long i=0;i<N;i++) {
		cin >> a[i];
	}

	//solve:
	for (long long q=0;q<Q;q++) {
		long long l,r,x; cin >> l >> r >> x;
		l--; r--;
		for (long long i=l;i<=r;i++) {
			a[i] += x;
		}
		long long val = 0;
		long long d[N];
		for (long long i=0;i<N;i++) {
			d[i]=0;
		}
		vector<long long> cv;
		for (long long i=1;i<N;i++) {
			val += abs(a[i]-a[i-1]);
			if (i<(N-1)) {
				/*if (!(((a[i-1]<a[i])&&(a[i]<a[i+1]))||((a[i-1]>a[i])&&(a[i]>a[i+1])))) {
					val -= min(abs(a[i]-a[i-1]),abs(a[i]-a[i+1]));
				}*/
				if ((a[i-1]<a[i])&&(a[i]>a[i+1])) {
					d[i]=1;
				} else if ((a[i-1]>a[i])&&(a[i]>a[i+1])) {
					d[i]=-1;
				}
				if ((d[i] != 0)&&(cv.size()==0)) {
					cv.push_back(i-1); cv.push_back(i);
				} else if (d[i] != 0) {
					cv.push_back(i);
				} else if (cv.size()!=0) {
					cv.push_back(i);
					long long K = cv.size();
					long long s1 = 0; long long s2 = 0;
					for (long long j=0;j<(K-1);j+=2) {
						s1 += abs(cv[j+1]-cv[j]);
					}
					for (long long j=1;j<(K-1);j+=2) {
						s2 += abs(cv[j+1]-cv[j]);
					}
					val -= min(s1,s2);
					cv.clear();
				}
			}
		}
		cout << val <<"\n";
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -