Submission #48401

#TimeUsernameProblemLanguageResultExecution timeMemory
48401PajarajaSimple game (IZhO17_game)C++17
100 / 100
97 ms5520 KiB
#include <bits/stdc++.h> using namespace std; int bit[1000007],a[100007]; int sum(int pos) { int sol=0; while(pos) { sol+=bit[pos]; pos-=(pos&-pos); } return sol; } void upd(int x,int pos) { while(pos<=1000000) { bit[pos]+=x; pos+=(pos&-pos); } } int main() { int n,m; scanf("%d%d",&n,&m); for(int i=0;i<n;i++) scanf("%d",&a[i]); for(int i=0;i<n-1;i++) { upd(1,min(a[i],a[i+1])); upd(-1,max(a[i],a[i+1])); } for(int i=0;i<m;i++) { int t; scanf("%d",&t); if(t==1) { int x,y; scanf("%d%d",&x,&y); x--; if(x!=0) { upd(-1,min(a[x],a[x-1])); upd(1,max(a[x],a[x-1])); } if(x!=n-1) { upd(-1,min(a[x],a[x+1])); upd(1,max(a[x],a[x+1])); } a[x]=y; if(x!=0) { upd(1,min(a[x],a[x-1])); upd(-1,max(a[x],a[x-1])); } if(x!=n-1) { upd(1,min(a[x],a[x+1])); upd(-1,max(a[x],a[x+1])); } } else {int x; scanf("%d",&x); printf("%d\n",sum(x));} } }

Compilation message (stderr)

game.cpp: In function 'int main()':
game.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~
game.cpp:26:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<n;i++) scanf("%d",&a[i]);
                       ~~~~~^~~~~~~~~~~~
game.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&t);
   ~~~~~^~~~~~~~~
game.cpp:39:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d%d",&x,&y);
    ~~~~~^~~~~~~~~~~~~~
game.cpp:63:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   else {int x; scanf("%d",&x); printf("%d\n",sum(x));}
                ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...