Submission #331550

# Submission time Handle Problem Language Result Execution time Memory
331550 2020-11-28T22:06:22 Z jovan_b Simple game (IZhO17_game) C++17
100 / 100
293 ms 5356 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

const int MAX = 1000000;

int h[MAX+5];

int bit[MAX+5];

void upd(int x, int val){
    while(x <= MAX+1){
        bit[x] += val;
        x += x & -x;
    }
}

int query(int x){
    int res = 0;
    while(x){
        res += bit[x];
        x -= x & -x;
    }
    return res;
}

int main(){
    ios_base::sync_with_stdio(false);
	cout.precision(10);
	cout << fixed;

    int n, m;
    cin >> n >> m;
    for(int i=1; i<=n; i++){
        cin >> h[i];
    }
    for(int i=2; i<=n; i++){
        upd(min(h[i-1], h[i]), 1);
        upd(max(h[i-1], h[i])+1, -1);
    }
    while(m--){
        int t;
        cin >> t;
        if(t == 1){
            int i, y;
            cin >> i >> y;
            if(i > 1){
                upd(min(h[i-1], h[i]), -1);
                upd(max(h[i-1], h[i])+1, 1);
            }
            if(i < n){
                upd(min(h[i+1], h[i]), -1);
                upd(max(h[i+1], h[i])+1, 1);
            }
            h[i] = y;
            if(i > 1){
                upd(min(h[i-1], h[i]), 1);
                upd(max(h[i-1], h[i])+1, -1);
            }
            if(i < n){
                upd(min(h[i+1], h[i]), 1);
                upd(max(h[i+1], h[i])+1, -1);
            }
        }
        else{
            int y;
            cin >> y;
            cout << query(y) << "\n";
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 4 ms 4076 KB Output is correct
3 Correct 4 ms 4076 KB Output is correct
4 Correct 4 ms 4076 KB Output is correct
5 Correct 4 ms 4076 KB Output is correct
6 Correct 4 ms 4076 KB Output is correct
7 Correct 4 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 4 ms 4076 KB Output is correct
3 Correct 4 ms 4076 KB Output is correct
4 Correct 4 ms 4076 KB Output is correct
5 Correct 4 ms 4076 KB Output is correct
6 Correct 4 ms 4076 KB Output is correct
7 Correct 4 ms 364 KB Output is correct
8 Correct 253 ms 1004 KB Output is correct
9 Correct 269 ms 5228 KB Output is correct
10 Correct 289 ms 5356 KB Output is correct
11 Correct 251 ms 1004 KB Output is correct
12 Correct 262 ms 1516 KB Output is correct
13 Correct 293 ms 1516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 4 ms 4076 KB Output is correct
3 Correct 4 ms 4076 KB Output is correct
4 Correct 4 ms 4076 KB Output is correct
5 Correct 4 ms 4076 KB Output is correct
6 Correct 4 ms 4076 KB Output is correct
7 Correct 4 ms 364 KB Output is correct
8 Correct 253 ms 1004 KB Output is correct
9 Correct 269 ms 5228 KB Output is correct
10 Correct 289 ms 5356 KB Output is correct
11 Correct 251 ms 1004 KB Output is correct
12 Correct 262 ms 1516 KB Output is correct
13 Correct 293 ms 1516 KB Output is correct
14 Correct 193 ms 4972 KB Output is correct
15 Correct 189 ms 4992 KB Output is correct
16 Correct 188 ms 4972 KB Output is correct
17 Correct 183 ms 4972 KB Output is correct
18 Correct 190 ms 5228 KB Output is correct