Submission #494945

# Submission time Handle Problem Language Result Execution time Memory
494945 2021-12-17T16:47:33 Z Ronin13 Simple game (IZhO17_game) C++14
100 / 100
60 ms 6812 KB
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define inf 1e9+1
#define linf 1e18+1
using namespace std;
const int NMAX=1e6+1;
vector<int>fen(NMAX);
int lsb(int x){
    return x&-x;
}
int n;
void add(int pos,int val){
    while(pos<=n){
        fen[pos]+=val;
        pos+=lsb(pos);
    }
}

int sum(int pos){
    int ss=0;
    while(pos){
        ss+=fen[pos];
        pos-=lsb(pos);
    }
    return ss;
}

void solve(){
    n=1e6;
    int m;cin>>m;
    int q;cin>>q;
    int h[m+1];
    for(int i=1;i<=m;i++){
        cin>>h[i];
    }
    for(int i=2;i<=m;i++){
        int r=max(h[i],h[i-1]);
        int l=min(h[i],h[i-1]);
        add(l,1);
        if(r!=1e6)add(r+1,-1);
    }
    while(q--){
        int ind;cin>>ind;
        if(ind==2){
            int pos;cin>>pos;
            cout<<sum(pos)<<"\n";
        }
        else{
            int pos,val;cin>>pos>>val;
            if(pos>1){
                int r=max(h[pos],h[pos-1]);
                int l=min(h[pos],h[pos-1]);
                add(l,-1);
                if(r!=1e6)add(r+1,1);
            }
            if(pos<m){
                int r=max(h[pos],h[pos+1]);
                int l=min(h[pos],h[pos+1]);
                add(l,-1);
                if(r!=1e6)add(r+1,1);
            }
            h[pos]=val;
            if(pos>1){
                int r=max(h[pos],h[pos-1]);
                int l=min(h[pos],h[pos-1]);
                add(l,1);
                if(r!=1e6)add(r+1,-1);
            }
            if(pos<m){
                int r=max(h[pos],h[pos+1]);
                int l=min(h[pos],h[pos+1]);
                add(l,1);
                if(r!=1e6)add(r+1,-1);
            }
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int test=1;//cin>>test;
    while(test--)solve();
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 4172 KB Output is correct
2 Correct 2 ms 4176 KB Output is correct
3 Correct 3 ms 4144 KB Output is correct
4 Correct 3 ms 4176 KB Output is correct
5 Correct 3 ms 4176 KB Output is correct
6 Correct 2 ms 4252 KB Output is correct
7 Correct 2 ms 4252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4172 KB Output is correct
2 Correct 2 ms 4176 KB Output is correct
3 Correct 3 ms 4144 KB Output is correct
4 Correct 3 ms 4176 KB Output is correct
5 Correct 3 ms 4176 KB Output is correct
6 Correct 2 ms 4252 KB Output is correct
7 Correct 2 ms 4252 KB Output is correct
8 Correct 35 ms 5504 KB Output is correct
9 Correct 43 ms 6768 KB Output is correct
10 Correct 43 ms 6812 KB Output is correct
11 Correct 34 ms 5468 KB Output is correct
12 Correct 40 ms 6568 KB Output is correct
13 Correct 41 ms 6648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4172 KB Output is correct
2 Correct 2 ms 4176 KB Output is correct
3 Correct 3 ms 4144 KB Output is correct
4 Correct 3 ms 4176 KB Output is correct
5 Correct 3 ms 4176 KB Output is correct
6 Correct 2 ms 4252 KB Output is correct
7 Correct 2 ms 4252 KB Output is correct
8 Correct 35 ms 5504 KB Output is correct
9 Correct 43 ms 6768 KB Output is correct
10 Correct 43 ms 6812 KB Output is correct
11 Correct 34 ms 5468 KB Output is correct
12 Correct 40 ms 6568 KB Output is correct
13 Correct 41 ms 6648 KB Output is correct
14 Correct 55 ms 6780 KB Output is correct
15 Correct 59 ms 6812 KB Output is correct
16 Correct 60 ms 6784 KB Output is correct
17 Correct 59 ms 6780 KB Output is correct
18 Correct 52 ms 6772 KB Output is correct