Submission #499658

# Submission time Handle Problem Language Result Execution time Memory
499658 2021-12-29T07:33:43 Z beksultan04 Simple game (IZhO17_game) C++14
0 / 100
12 ms 18508 KB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define pii pair<int,int>
#define ret return
#define fr first
#define sc second
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define nosol puts("-1");
#define pb push_back
#define endi puts("");
#define ordered_set tree <int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N = 5e6+12,INF = 1e9+7;
int a[N],n,der[N],b[N],lp[N];

void push(int v,int l,int r){
	if (l == r){
		der[v] += lp[v];
		lp[v] = 0;
	}
	else {
		lp[v<<1] += lp[v];
		lp[v<<1|1] += lp[v];
		lp[v] = 0;
	}
}

void update(int v,int l,int r,int ql,int qr,int x){
	if (r < ql || qr < l){
		push(v,l,r);
		ret ;
	}
	if (ql <= l && r <= qr){
		lp[v] += x;
		push(v,l,r);
		ret ;
	}
	push(v,l,r);
	int m = l+r>>1;
	update(v<<1,l,m,ql,qr,x);
	update(v<<1|1,m+1,r,ql,qr,x);
}

int get_ans(int v,int l,int r,int pos){
	push(v,l,r);
	if (l == r){
		ret der[v]+lp[v];
	}
	int m = l+r>>1;
	if (m < pos)
		ret get_ans(v<<1|1,m+1,r,pos);
	else ret get_ans(v<<1,l,m,pos);
	
}

main(){
	int n,m,i,j;
	cin>>n>>m;
	
	for (i=1;i<=n;++i){
		cin>>a[i];
	}
	for (i=2;i<=n;++i)
		update(1,1,1000000,min(a[i],a[i-1]),max(a[i],a[i-1]),1);
		
	for (i=2;i<n;++i)
		update(1,1,1000000,a[i],a[i],-1);
		
	while (m--){
		int t;
		cin>>t;
		if (t == 2){
			int x;
			cin>>x;
			cout <<get_ans(1,1,1000000,x)<<"\n";
		}
		else {
			int pos,x;
			cin>>pos>>x;
			if (pos > 1){
				update(1,1,1000000,min(a[pos],a[pos-1]),max(a[pos],a[pos-1]),-1);
			}
			if (pos < n){
				update(1,1,1000000,min(a[pos],a[pos+1]),max(a[pos],a[pos+1]),-1);
			}
			a[pos] = x;
			
			if (pos > 1){
				update(1,1,1000000,min(a[pos],a[pos-1]),max(a[pos],a[pos-1]),1);
			}
			if (pos < n){
				update(1,1,1000000,min(a[pos],a[pos+1]),max(a[pos],a[pos+1]),1);
			}
		}
	}
	
}








Compilation message

game.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int, long long int)':
game.cpp:46:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |  int m = l+r>>1;
      |          ~^~
game.cpp: In function 'long long int get_ans(long long int, long long int, long long int, long long int)':
game.cpp:56:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   56 |  int m = l+r>>1;
      |          ~^~
game.cpp: At global scope:
game.cpp:63:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   63 | main(){
      | ^~~~
game.cpp: In function 'int main()':
game.cpp:64:12: warning: unused variable 'j' [-Wunused-variable]
   64 |  int n,m,i,j;
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 280 KB Output is correct
2 Correct 12 ms 18508 KB Output is correct
3 Incorrect 12 ms 18060 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 280 KB Output is correct
2 Correct 12 ms 18508 KB Output is correct
3 Incorrect 12 ms 18060 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 280 KB Output is correct
2 Correct 12 ms 18508 KB Output is correct
3 Incorrect 12 ms 18060 KB Output isn't correct
4 Halted 0 ms 0 KB -