Submission #679765

# Submission time Handle Problem Language Result Execution time Memory
679765 2023-01-09T07:18:31 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]);
}
int 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 mx - mn;
}

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 mn = INF, mx = -INF;
		for(int i = 0; i < n; i++){
			int res = get(i, n);
			if(mx - mn == res && res){
				ans += res;
				mx = -INF, mn = INF;
			}
			mx = max(a[i], mx);
			mn = min(a[i], mn);
		}
		ans += 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 -