Submission #672420

# Submission time Handle Problem Language Result Execution time Memory
672420 2022-12-16T03:45:15 Z Baytoro Simple game (IZhO17_game) C++17
0 / 100
11 ms 16756 KB
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define int long long
#define endl '\n'
void fopn(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const int INF=1e18,mod=1e9+7;
vector<int> tree;
int sz;
void innit(int n){
	sz=1;
	while(sz<n)
		sz*=2;
	tree.assign(2*sz-1,0);
}
void add(int l, int r, int v,int x, int lx, int rx){
	if(l>=rx || r<=lx)
		return;
	if(lx>=l && rx<=r){
		tree[x]+=v;
		return;
	}
	int m=(lx+rx)/2;
	add(l,r,v,2*x+1,lx,m);
	add(l,r,v,2*x+2,m,rx);
}
void add(int l, int r, int v){
	add(l,r,v,0,0,sz);
}
int get(int i, int x, int lx, int rx){
	if(rx==lx+1)
		return tree[x];
	int m=(lx+rx)/2;
	if(i<m)
		return get(i,2*x+1,lx,m)+tree[x];
	else
		return get(i,2*x+2,m,rx)+tree[x];
}
int get(int i){
	return get(i,0,0,sz);
}
void st(int i, int v, int x, int lx, int rx){
	if(rx-lx==1){
		tree[x]=v;
		return;
	}
	int m=(lx+rx)/2;
	if(i<m)
		st(i,v,2*x+1,lx,m);
	else
		st(i,v,2*x+2,m,rx);
	tree[x]=tree[2*x+1]+tree[2*x+2];
}
void st(int i, int v){
	st(i,v,0,0,sz);
}
int n,m;
void solve(){
	cin>>n>>m;
	vector<int> vec(n);
	for(int i=0;i<n;i++)
		cin>>vec[i];
	innit(1e6+5);
	for(int i=1;i<n;i++){
		add(min(vec[i],vec[i-1]),max(vec[i],vec[i-1])+1,1);
	}
	while(m--){
		int t;cin>>t;
		if(t==2){
			int x;cin>>x;
			cout<<get(x-1)<<endl;
		}
		else{
			int pos,val;cin>>pos>>val;
			pos--;
			if(pos>0)
				add(min(vec[pos],vec[pos-1]),max(vec[pos],vec[pos-1])+1,-1);
			if(pos<n-1)
				add(min(vec[pos],vec[pos+1]),max(vec[pos],vec[pos+1])+1,-1);
			vec[pos]=val;
			if(pos>0)
				add(min(vec[pos],vec[pos-1]),max(vec[pos],vec[pos-1])+1,1);
			if(pos<n-1)
				add(min(vec[pos],vec[pos+1]),max(vec[pos],vec[pos+1])+1,1);
		}
	}
}
main(){
	//ios;
	int T=1;
	//cin>>T;
	while(T--){
		solve();
	}
}

Compilation message

game.cpp:96:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   96 | main(){
      | ^~~~
game.cpp: In function 'void fopn(std::string)':
game.cpp:12:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
game.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16724 KB Output is correct
2 Correct 11 ms 16724 KB Output is correct
3 Incorrect 11 ms 16756 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16724 KB Output is correct
2 Correct 11 ms 16724 KB Output is correct
3 Incorrect 11 ms 16756 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16724 KB Output is correct
2 Correct 11 ms 16724 KB Output is correct
3 Incorrect 11 ms 16756 KB Output isn't correct
4 Halted 0 ms 0 KB -