Submission #679772

# Submission time Handle Problem Language Result Execution time Memory
679772 2023-01-09T07:36:07 Z faribourz Sjeckanje (COCI21_sjeckanje) C++14
0 / 110
1 ms 340 KB
// Only GOD
// believe in yourself
// Nemidam Del Be In Darde Donya!
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define int ll
typedef long double ld;
typedef pair<int, int> pii;
 
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define bit(x, y) ((x >> y)&1)
#define sz(x) (int)x.size()
#define kill(x) return cout << x << '\n', void()
#define KILL(x) return cout << x << '\n', 0
 
const int N = 2e5+100;
const int INF = 1e18+10;
int a[N];
int n;
int node[N << 2], node2[N << 2];
void upd(int x, int p){
	p += n;
	node[p] += x;
	node2[p] += x;
	p >>= 1;
	for(;p;p>>=1)
		node[p] = min(node[p*2], node[p*2+1]), node2[p] = max(node2[p*2], node2[p*2+1]);
}
pii get(int l, int r){
	l += n, r += n;
	int mx = -INF, mn = INF;
	while(l < r){
		if(l & 1){
			mx = max(mx, node2[l]), mn = min(mn, node[l++]);
		}
		if(r & 1)
			mx = max(mx, node2[--r]), mn = min(mn, node[r]);
		l >>= 1, r >>= 1;
	}
	return {mn, mx};
}

int32_t main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int q;
	cin >> n >> q;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = 0; i < n; i++)
		upd(a[i], i);
	while(q--){
		int L, R, x;
		cin >> L >> R >> x;
		L--;
		for(int i = L; i < R; i++)
			a[i] += x, upd(x, i);
		int ans =0;
		int l = 0;
		while(l < n){
			pii res = get(l, n);
			int mn = INF, mx = -INF;
			while(a[l] != res.F && a[l] != res.S){
				mn = min(a[l], mn);
				mx = max(mx, a[l]);
				l++;
			}
			if(a[l] == res.F){
				while(a[l] != res.S)
					l++;
			}
			else{
				while(a[l] != res.F)
					l++;
			}
			l++;
			ans += res.S-res.F;
			ans += max(0ll, mx - mn);
		}
		cout << ans << '\n';

	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -