Submission #85271

# Submission time Handle Problem Language Result Execution time Memory
85271 2018-11-19T02:30:24 Z mra2322001 Simple game (IZhO17_game) C++14
0 / 100
2 ms 700 KB
#include <bits/stdc++.h>
#define f0(i, n) for(int i(0); i < (n); i++)
#define f1(i, n) for(int i(1); i <= n; i++)

using namespace std;
typedef long long ll;
const int N = 100002;

int n, q, a[N], t[1000002], b[N], c[N];

void up1(int k, int l, int r, int i, int j, int x){
    if(r < i || l > j) return ;
    if(l >= i && r <= j){
        t[k] += x;
        return ;
    }
    int m = (l + r)/2;
    up1(k*2, l, m, i, j, x);
    up1(k*2 + 1, m + 1, r, i, j, x);
}

int get1(int k, int l, int r, int i){
    if(l==r) return t[k];
    int m = (l + r)/2;
    if(i <= m) return t[k] + get1(k*2, l, m, i);
    return t[k] + get1(k*2 + 1, m + 1, r, i);
}

void up(int k1, int k2, int x){
    if(k1 > k2) return ;
    up1(1, 1, 1000000, k1, k2, x);
}

void solve(){
    int h; cin >> h;
    int x = get1(1, 1, 1000000, h);
    cout << x << endl;
}

int main(){
    ios_base::sync_with_stdio(0);

    cin >> n >> q;
    f1(i, n) cin >> a[i];
    for(int i = 2; i <= n; i++){
        b[i - 1] = min(a[i - 1], a[i]);
        c[i - 1] = max(a[i - 1], a[i]);
        up(b[i - 1] + 1, c[i - 1] - 1, 1);
    }
    while(q--){
        int type; cin >> type;
        if(type==2) solve();
        else{
            int i, x; cin >> i >> x;
            if(i > 1){
                up(b[i - 1] + 1, c[i - 1] - 1, -1);
                b[i - 1] = min(a[i - 1], x);
                c[i - 1] = max(a[i - 1], x);
                up(b[i - 1] + 1, c[i - 1] - 1, 1);
            }
            if(i < n){
                up(b[i] + 1, c[i] - 1, -1);
                b[i] = min(a[i + 1], x);
                c[i] = max(a[i + 1], x);
                up(b[i] + 1, c[i] - 1, 1);
            }
            a[i] += x;
        }
    }
  
  
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Runtime error 2 ms 700 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Runtime error 2 ms 700 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Runtime error 2 ms 700 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -