Submission #63361

#TimeUsernameProblemLanguageResultExecution timeMemory
63361TenuunSimple game (IZhO17_game)C++17
100 / 100
288 ms22708 KiB
#include<bits/stdc++.h>
 
using namespace std;
 
int tr[1000001];
 
void update(int ind, int val){
	while(ind<=1000001){
		tr[ind]+=val;
		ind+=ind&-ind;
	}
}
 
int get(int ind){
	int ans=0;
	while(ind){
		ans+=tr[ind];
		ind-=ind&-ind;
	}
	return ans;
}
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	memset(tr, 0, sizeof tr);
	int n, m, pos, val, t;
	cin >> n >> m;
	int a[n+1];
	for(int i=1; i<=n; i++){
		cin >> a[i];
		if(i>1){
			update(min(a[i], a[i-1]), 1);
			update(max(a[i], a[i-1])+1, -1);
		}
	}
	while(m--){
		cin >> t;
		if(t==1){
			cin >> pos >> val;
			if(pos>1){
				update(min(a[pos], a[pos-1]), -1);
				update(max(a[pos], a[pos-1])+1, 1);
			}
			if(pos+1<=n){
				update(min(a[pos], a[pos+1]), -1);
				update(max(a[pos], a[pos+1])+1, 1);
			}
			a[pos]=val;
			if(pos>1){
				update(min(a[pos], a[pos-1]), 1);
				update(max(a[pos], a[pos-1])+1, -1);
			}
			if(pos+1<=n){
				update(min(a[pos], a[pos+1]), 1);
				update(max(a[pos], a[pos+1])+1, -1);
			}
		}
		else{
			cin >> val;
			cout << get(val) << endl;
		}
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...