답안 #679769

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
679769 2023-01-09T07:26:56 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;
		l = 0;
		while(l < n){
			int res = get(l, n);
			int mn = a[l], mx = a[l];
			while(mx - mn != res){
				mn = min(a[++l], mn), mx = max(mx, a[l]);
			}
			ans += res;
			l++;
		}
		cout << ans << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -