Submission #499660

# Submission time Handle Problem Language Result Execution time Memory
499660 2021-12-29T07:35:44 Z beksultan04 Simple game (IZhO17_game) C++14
0 / 100
8 ms 10188 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 update(int v,int l,int r,int ql,int qr,int x){
	if (r < ql || qr < l){
		ret ;
	}
	if (ql <= l && r <= qr){
		der[v] += x;
		ret ;
	}
	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){
	if (l == r){
		ret der[v];
	}
	int m = l+r>>1;
	if (m < pos)
		ret der[v] + get_ans(v<<1|1,m+1,r,pos);
	else ret der[v] + 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:31:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |  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:40:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |  int m = l+r>>1;
      |          ~^~
game.cpp: At global scope:
game.cpp:47:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   47 | main(){
      | ^~~~
game.cpp: In function 'int main()':
game.cpp:48:12: warning: unused variable 'j' [-Wunused-variable]
   48 |  int n,m,i,j;
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 7 ms 10188 KB Output is correct
3 Incorrect 8 ms 9844 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 7 ms 10188 KB Output is correct
3 Incorrect 8 ms 9844 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 7 ms 10188 KB Output is correct
3 Incorrect 8 ms 9844 KB Output isn't correct
4 Halted 0 ms 0 KB -