답안 #1102848

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1102848 2024-10-19T05:06:11 Z Muhammet Simple game (IZhO17_game) C++17
0 / 100
14 ms 31568 KB
#include <bits/stdc++.h>

using namespace std;

int n, m, ans;

vector <int> st, lz;

void f(int nd, int l, int r){
	st[nd] += ((r-l+1) * (lz[nd]));
	if(l != r){
		lz[nd*2] += lz[nd];
		lz[nd*2+1] += lz[nd];
	}
	lz[nd] = 0;
	return;
}

int upd(int nd, int l, int r, int x, int y, int vl){
	f(nd,l,r);
	if(l > y or r < x) return st[nd];
	if(l >= x and r <= y){
		lz[nd] += vl;
		f(nd,l,r);
		// st[nd] += ((r-l+1)*(lz[nd]));
		// if(l != r){
		// 	lz[nd*2] += vl;
		// 	lz[nd*2+1] += vl;
		// }
		return st[nd];
	}
	int md = (l + r) / 2;
	return st[nd] = (upd(nd*2,l,md,x,y,vl) + upd(nd*2+1,md+1,r,x,y,vl));
}

int fnd(int nd, int l, int r, int ind){
	f(nd,l,r);
	if((r < ind) or (l > ind)) return st[nd];
	if(l == r) {
		ans = st[nd];
		return st[nd];
	}
	int md = (l + r) / 2;
	return st[nd] = (fnd(nd*2,l,md,ind) + fnd(nd*2+1,md+1,r,ind));
}

int main(){
	cin >> n >> m;
	vector <int> a(n+1);
	int mx = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		mx = max(mx,a[i]);
	}
	st.assign(mx*4,0);
	lz.assign(mx*4,0);
	for(int i = 2; i <= n; i++){
		if(a[i-1]+1 <= a[i]-1){
			upd(1,1,mx,a[i-1]+1,a[i]-1,1);
		}
	}
	for(int i = 1; i <= m; i++){
		int t;
		cin >> t;
		if(t == 1){
			int ind, vl;
			cin >> ind >> vl;
			if(ind > 1){
				if(a[ind-1] + 1 <= a[ind] - 1){
					upd(1,1,mx,a[ind-1]+1,a[ind]-1,-1);
				}
			}
			if(ind < n){
				if(a[ind] + 1 <= a[ind+1] - 1){
					upd(1,1,mx,a[ind]+1,a[ind+1]-1,-1);
				}
			}
			a[ind] = vl;
			if(ind > 1){
				if(a[ind-1] + 1 <= a[ind] - 1){
					upd(1,1,mx,a[ind-1]+1,a[ind]-1,1);
				}
			}
			if(ind < n){
				if(a[ind] + 1 <= a[ind+1] - 1){
					upd(1,1,mx,a[ind]+1,a[ind+1]-1,1);
				}
			}
		}
		else {
			int x;
			cin >> x;
			ans = 0;
			fnd(1,1,mx,x);
			cout << ans+1 << '\n';
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 14 ms 31568 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 14 ms 31568 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 14 ms 31568 KB Output isn't correct
3 Halted 0 ms 0 KB -