제출 #672424

#제출 시각아이디문제언어결과실행 시간메모리
672424BaytoroSimple game (IZhO17_game)C++17
100 / 100
325 ms19728 KiB
#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+1,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+1); for(int i=1;i<=n;i++) cin>>vec[i]; innit(1e6+5); for(int i=2;i<=n;i++){ add(min(vec[i],vec[i-1]),max(vec[i],vec[i-1]),1); } while(m--){ int t;cin>>t; if(t==2){ int x;cin>>x; cout<<get(x)<<endl; } else{ int pos,val;cin>>pos>>val; if(pos>1) add(min(vec[pos],vec[pos-1]),max(vec[pos],vec[pos-1]),-1); if(pos<n) add(min(vec[pos],vec[pos+1]),max(vec[pos],vec[pos+1]),-1); vec[pos]=val; if(pos>1) add(min(vec[pos],vec[pos-1]),max(vec[pos],vec[pos-1]),1); if(pos<n) add(min(vec[pos],vec[pos+1]),max(vec[pos],vec[pos+1]),1); } } } main(){ //ios; int T=1; //cin>>T; while(T--){ solve(); } }

컴파일 시 표준 에러 (stderr) 메시지

game.cpp:95:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   95 | 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...