Submission #333896

# Submission time Handle Problem Language Result Execution time Memory
333896 2020-12-08T02:35:14 Z tengiz05 Simple game (IZhO17_game) C++17
0 / 100
5 ms 5484 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
const int mod = 1e9+7, N = 1e6+5;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val);}
int a[N], n, m, k;
int t[N*2];
int mx = 8;
int query(int p){
	int ans = 0;
	for(p+=mx;p>0;p>>=1)ans += t[p];
	return ans;
}
void update(int l, int r, int val){
	for(l += mx, r += mx; l <= r; l>>=1, r>>=1){
		if(l%2 == 1)t[l++] += val;
		if(r%2 == 0)t[r--] += val;
	}
}
void show(){
	for(int i=0;i<mx;i++)cout << t[i] << ' ';
	cout << '\n';
	
	for(int i=0;i<mx;i++)cout << t[i+mx] << ' ';
	cout << '\n';
	
}
void solve(int test_case){
	int i, j;
	cin >> n >> m;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
//	update(min(a[0], a[1]), max(a[0], a[1]), 1);
	for(i=1;i<n;i++){
		update(min(a[i], a[i-1]), max(a[i], a[i-1]), 1);
	}
	while(m--){
		int typ;
		cin >> typ;
		if(typ == 1){
			//update
			int pos, val;
			cin >> pos >> val;pos--;
			if(pos != 0){
				update(min(a[pos], a[pos-1]), max(a[pos], a[pos-1]), -1);
			}
			if(pos != n-1){
				update(min(a[pos], a[pos+1]), max(a[pos], a[pos+1]), -1);
			}
			a[pos] = val;
			if(pos != 0){
				update(min(a[pos], a[pos-1]), max(a[pos], a[pos-1]), 1);
			}
			if(pos != n-1){
				update(min(a[pos], a[pos+1]), max(a[pos], a[pos+1]), 1);
			}
			
		}else {
			//query
			int h;
			cin >> h;
			cout << query(h) << '\n';
		}
	}
	return;
}

signed main(){
	FASTIO;
#define MULTITEST 0
#if MULTITEST
	int ___T;
	cin >> ___T;
	for(int T_CASE = 1; T_CASE <= ___T; T_CASE++)
		solve(T_CASE);
#else
	solve(1);
#endif
	return 0;
}


Compilation message

game.cpp: In function 'void solve(long long int)':
game.cpp:37:9: warning: unused variable 'j' [-Wunused-variable]
   37 |  int i, j;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 5 ms 5484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 5 ms 5484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 5 ms 5484 KB Output isn't correct
3 Halted 0 ms 0 KB -