Submission #172678

# Submission time Handle Problem Language Result Execution time Memory
172678 2020-01-02T10:48:08 Z RafaelSus Simple game (IZhO17_game) C++14
100 / 100
355 ms 19684 KB
#include <bits/stdc++.h>
 
using namespace std;
const int N = 2e5 + 5;
typedef long long ll;
const ll inf=1e15;
#define pb push_back
const int INF=(0x3f3f3f3f);

int h[N];
int T[N*20];
int lazy[N*20];

inline void pushdown(int v,int tl,int tr){
  if(lazy[v]==0)return;
  int tm=(tl+tr)/2;
  lazy[v+v]+=lazy[v];
  lazy[v+v+1]+=lazy[v];
  T[v+v]+=(tm-tl+1)*lazy[v];
  T[v+v+1]+=(tr-tm)*lazy[v];
  lazy[v]=0;
}

void update(int v,int tl,int tr,int l,int r,int val){
  if(l>r)return;
  if(l<=tl&&r>=tr){
    T[v]+=(tr-tl+1)*val;
    lazy[v]+=val;
    return;
  }
  pushdown(v,tl,tr);
  int tm=(tl+tr)/2;
  if(l<=tm)update(v+v,tl,tm,l,r,val);
  if(r>=tm+1)update(v+v+1,tm+1,tr,l,r,val);
  T[v]=T[v+v]+T[v+v+1];
}

int get(int v,int tl,int tr,int pos){
  if(tl==tr){
    return T[v];
  }
  pushdown(v,tl,tr);
  int tm=(tl+tr)/2;
  if(pos<=tm)return get(v+v,tl,tm,pos);
  if(pos>tm)return get(v+v+1,tm+1,tr,pos);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);

  int n,m;
  cin>>n>>m;
  for(int i=1;i<=n;i++){
    cin>>h[i];
    if(i>1){
      update(1,1,1000000,min(h[i],h[i-1]),max(h[i],h[i-1]),+1);
    }
  }
  for(int i=0;i<m;i++){
    int com;
    cin>>com;
    if(com==1){
      int pos,val;
      cin>>pos>>val;
      if(pos==1){
        update(1,1,1000000,min(h[pos],h[pos+1]),max(h[pos],h[pos+1]),-1);
        h[pos]=val;
        update(1,1,1000000,min(h[pos],h[pos+1]),max(h[pos],h[pos+1]),+1);
      }else if(pos==n){
        update(1,1,1000000,min(h[pos],h[pos-1]),max(h[pos],h[pos-1]),-1);
        h[pos]=val;
        update(1,1,1000000,min(h[pos],h[pos-1]),max(h[pos],h[pos-1]),+1);
      }else{
        update(1,1,1000000,min(h[pos],h[pos+1]),max(h[pos],h[pos+1]),-1);
        update(1,1,1000000,min(h[pos],h[pos-1]),max(h[pos],h[pos-1]),-1);
        h[pos]=val;
        update(1,1,1000000,min(h[pos],h[pos+1]),max(h[pos],h[pos+1]),+1);
        update(1,1,1000000,min(h[pos],h[pos-1]),max(h[pos],h[pos-1]),+1);
      }
    }else{
      int H;
      cin>>H;
      cout<<get(1,1,1000000,H)<<'\n';
    }
  }
}

Compilation message

game.cpp: In function 'int get(int, int, int, int)':
game.cpp:46:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 420 KB Output is correct
2 Correct 17 ms 14840 KB Output is correct
3 Correct 17 ms 14428 KB Output is correct
4 Correct 17 ms 14632 KB Output is correct
5 Correct 17 ms 14840 KB Output is correct
6 Correct 17 ms 14812 KB Output is correct
7 Correct 13 ms 12800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 420 KB Output is correct
2 Correct 17 ms 14840 KB Output is correct
3 Correct 17 ms 14428 KB Output is correct
4 Correct 17 ms 14632 KB Output is correct
5 Correct 17 ms 14840 KB Output is correct
6 Correct 17 ms 14812 KB Output is correct
7 Correct 13 ms 12800 KB Output is correct
8 Correct 62 ms 1876 KB Output is correct
9 Correct 179 ms 19424 KB Output is correct
10 Correct 180 ms 19428 KB Output is correct
11 Correct 57 ms 1656 KB Output is correct
12 Correct 103 ms 3336 KB Output is correct
13 Correct 87 ms 19192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 420 KB Output is correct
2 Correct 17 ms 14840 KB Output is correct
3 Correct 17 ms 14428 KB Output is correct
4 Correct 17 ms 14632 KB Output is correct
5 Correct 17 ms 14840 KB Output is correct
6 Correct 17 ms 14812 KB Output is correct
7 Correct 13 ms 12800 KB Output is correct
8 Correct 62 ms 1876 KB Output is correct
9 Correct 179 ms 19424 KB Output is correct
10 Correct 180 ms 19428 KB Output is correct
11 Correct 57 ms 1656 KB Output is correct
12 Correct 103 ms 3336 KB Output is correct
13 Correct 87 ms 19192 KB Output is correct
14 Correct 355 ms 19468 KB Output is correct
15 Correct 348 ms 19420 KB Output is correct
16 Correct 351 ms 19532 KB Output is correct
17 Correct 351 ms 19632 KB Output is correct
18 Correct 349 ms 19684 KB Output is correct