Submission #883465

# Submission time Handle Problem Language Result Execution time Memory
883465 2023-12-05T10:12:05 Z NintsiChkhaidze Simple game (IZhO17_game) C++17
100 / 100
224 ms 20052 KB
#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define left (h<<1),l,(l + r)/2
#define right ((h<<1)|1),(l + r)/2 + 1,r
#define pii pair<int,int>
#define ll long long 
#define int ll //?
using namespace std;

const int N = 1e5 + 5;

int a[N],t[4000005],n;

void updd(int h,int l,int r,int L,int R,int val){
	if (r < L || R < l) return;
	if (L <= l && r <= R){
		t[h] += val;
		return;
	}

	updd(left,L,R,val);
	updd(right,L,R,val);
}

int get(int h,int l,int r,int idx){
	if (l == r) return t[h];
	if (idx > (l + r)/2) return t[h] + get(right,idx);
	return t[h] + get(left,idx);
}

void upd(int k,int dl){
	int l = k - 1,r = k;
	if (l < 1 || r > n) return;

	int x = a[l],y = a[r];
	if (x > y) swap(x,y);
	updd(1,1,1000000,x,y,dl);
}

signed main (){
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
	
	int q;
	cin>>n>>q;

	for (int i = 1; i <= n; i++){
		cin >> a[i];
		if (i > 1) upd(i,1);
	}

	while (q--){
		int tp;
		cin>>tp;
		if (tp == 1){
			int idx,val;
			cin>>idx>>val;

			upd(idx,-1);
			upd(idx+1,-1);

			a[idx] = val;

			upd(idx,1);
			upd(idx+1,1);
		}else{
			int x;
			cin>>x;
			cout<<get(1,1,1000000,x)<<endl;
		}
	}

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 4 ms 16988 KB Output is correct
3 Correct 4 ms 16988 KB Output is correct
4 Correct 4 ms 16988 KB Output is correct
5 Correct 4 ms 16988 KB Output is correct
6 Correct 4 ms 16988 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 4 ms 16988 KB Output is correct
3 Correct 4 ms 16988 KB Output is correct
4 Correct 4 ms 16988 KB Output is correct
5 Correct 4 ms 16988 KB Output is correct
6 Correct 4 ms 16988 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 136 ms 8276 KB Output is correct
9 Correct 195 ms 20032 KB Output is correct
10 Correct 177 ms 20052 KB Output is correct
11 Correct 132 ms 5984 KB Output is correct
12 Correct 168 ms 11392 KB Output is correct
13 Correct 139 ms 3156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 4 ms 16988 KB Output is correct
3 Correct 4 ms 16988 KB Output is correct
4 Correct 4 ms 16988 KB Output is correct
5 Correct 4 ms 16988 KB Output is correct
6 Correct 4 ms 16988 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 136 ms 8276 KB Output is correct
9 Correct 195 ms 20032 KB Output is correct
10 Correct 177 ms 20052 KB Output is correct
11 Correct 132 ms 5984 KB Output is correct
12 Correct 168 ms 11392 KB Output is correct
13 Correct 139 ms 3156 KB Output is correct
14 Correct 203 ms 19796 KB Output is correct
15 Correct 203 ms 19900 KB Output is correct
16 Correct 224 ms 19796 KB Output is correct
17 Correct 190 ms 19936 KB Output is correct
18 Correct 215 ms 19956 KB Output is correct