Submission #85267

# Submission time Handle Problem Language Result Execution time Memory
85267 2018-11-19T02:22:43 Z mra2322001 Simple game (IZhO17_game) C++14
0 / 100
6 ms 4372 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 up(int x, int y, int id){
    for(x; x <= 1000000; x += (x & -x)) t[x] += id;
    for(y = y + 1; y <= 1000000; y += (y & -y)) t[y] -= id;
}

int get1(int x){
    if(x <= 0) return 0;
    int res = 0;
    for(x; x > 0; x -= (x & -x)) res += t[x];
    return res;
}

void solve(){
    int h; cin >> h;
    int x = get1(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;
        }
    }
}

Compilation message

game.cpp: In function 'void up(int, int, int)':
game.cpp:12:10: warning: statement has no effect [-Wunused-value]
     for(x; x <= 1000000; x += (x & -x)) t[x] += id;
          ^
game.cpp: In function 'int get1(int)':
game.cpp:19:10: warning: statement has no effect [-Wunused-value]
     for(x; x > 0; x -= (x & -x)) res += t[x];
          ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 6 ms 4372 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 6 ms 4372 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 6 ms 4372 KB Output isn't correct
3 Halted 0 ms 0 KB -