Submission #72945

# Submission time Handle Problem Language Result Execution time Memory
72945 2018-08-27T09:32:16 Z win11905 Simple game (IZhO17_game) C++11
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5+5;
const int MX = 1e6;

int n, m, A[N];
int t[MX];

int get(int x) { return upper_bound(all(coor), x) - coor.begin(); }

void update(int x, int v) {
    for(; x <= MX; x += x & -x) t[x-1] += v;
}

int query(int x) {
    int v = 0;
    for(; x; x -= x & -x) v += t[x-1];
    return v;
}

int main() {
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; ++i) scanf("%d", A+i);
    for(int i = 1; i < n; ++i) {
        update(min(A[i], A[i+1]), 1);
        update(1 + max(A[i], A[i+1]), -1);
    } 
    for(int i = 0, a, b, c; i < m; ++i) {
        scanf("%d %d", &a, &b);
        if(a == 1) {
            scanf("%d", &c);
            if(b != 1) {
                update(min(A[b], A[b-1]), -1);
                update(1 + max(A[b], A[b-1]), 1);
                A[b] = c;
                update(min(A[b], A[b-1]), 1);
                update(1 + max(A[b], A[b-1]), -1);
            }
            if(b != n) {
                update(min(A[b], A[b+1]), -1);
                update(1 + max(A[b], A[b+1]), 1);
                A[b] = c;
                update(min(A[b], A[b+1]), 1);
                update(1 + max(A[b], A[b+1]), -1);
            }
        } else printf("%d\n", query(b)); 
    }
    
}

Compilation message

game.cpp: In function 'int get(int)':
game.cpp:10:41: error: 'coor' was not declared in this scope
 int get(int x) { return upper_bound(all(coor), x) - coor.begin(); }
                                         ^~~~
game.cpp:10:41: note: suggested alternative: 'floor'
 int get(int x) { return upper_bound(all(coor), x) - coor.begin(); }
                                         ^~~~
                                         floor
game.cpp:10:37: error: 'all' was not declared in this scope
 int get(int x) { return upper_bound(all(coor), x) - coor.begin(); }
                                     ^~~
game.cpp:10:37: note: suggested alternative: 'kill'
 int get(int x) { return upper_bound(all(coor), x) - coor.begin(); }
                                     ^~~
                                     kill
game.cpp: In function 'int main()':
game.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
game.cpp:24:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= n; ++i) scanf("%d", A+i);
                                 ~~~~~^~~~~~~~~~~
game.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~
game.cpp:32:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &c);
             ~~~~~^~~~~~~~~~