Submission #36953

# Submission time Handle Problem Language Result Execution time Memory
36953 2017-12-19T14:57:01 Z top34051 Simple game (IZhO17_game) C++14
100 / 100
159 ms 6312 KB
#include<bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 5;
const int maxv = 1e6;

int n,m;
int p[maxn], tree[maxv+5];

void add(int x,int val) {
    while(x<=maxv) {
        tree[x] += val;
        x += x&-x;
    }
}

int sum(int x) {
    int ans = 0;
    while(x>0) {
        ans += tree[x];
        x -= x&-x;
    }
    return ans;
}

void update(int x,int y,int val) {
    if(x>y) swap(x,y);
    add(x,val); add(y+1,-val);
}

int main() {
    int type,x,val;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d",&p[i]);
    for(int i=1;i<n;i++) update(p[i], p[i+1], 1);
    while(m--) {
        scanf("%d",&type);
        if(type==1) {
            scanf("%d%d",&x,&val);
            if(x>1) update(p[x-1], p[x], -1);
            if(x<n) update(p[x], p[x+1], -1);
            p[x] = val;
            if(x>1) update(p[x-1], p[x], 1);
            if(x<n) update(p[x], p[x+1], 1);
        }
        else {
            scanf("%d",&x);
            printf("%d\n",sum(x));
        }
    }
}

Compilation message

game.cpp: In function 'int main()':
game.cpp:33:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
                        ^
game.cpp:34:44: 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",&p[i]);
                                            ^
game.cpp:37:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&type);
                          ^
game.cpp:39:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d",&x,&val);
                                  ^
game.cpp:47:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&x);
                           ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6312 KB Output is correct
2 Correct 0 ms 6312 KB Output is correct
3 Correct 3 ms 6312 KB Output is correct
4 Correct 0 ms 6312 KB Output is correct
5 Correct 3 ms 6312 KB Output is correct
6 Correct 3 ms 6312 KB Output is correct
7 Correct 0 ms 6312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6312 KB Output is correct
2 Correct 0 ms 6312 KB Output is correct
3 Correct 3 ms 6312 KB Output is correct
4 Correct 0 ms 6312 KB Output is correct
5 Correct 3 ms 6312 KB Output is correct
6 Correct 3 ms 6312 KB Output is correct
7 Correct 0 ms 6312 KB Output is correct
8 Correct 73 ms 6312 KB Output is correct
9 Correct 89 ms 6312 KB Output is correct
10 Correct 93 ms 6312 KB Output is correct
11 Correct 66 ms 6312 KB Output is correct
12 Correct 76 ms 6312 KB Output is correct
13 Correct 66 ms 6312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6312 KB Output is correct
2 Correct 0 ms 6312 KB Output is correct
3 Correct 3 ms 6312 KB Output is correct
4 Correct 0 ms 6312 KB Output is correct
5 Correct 3 ms 6312 KB Output is correct
6 Correct 3 ms 6312 KB Output is correct
7 Correct 0 ms 6312 KB Output is correct
8 Correct 73 ms 6312 KB Output is correct
9 Correct 89 ms 6312 KB Output is correct
10 Correct 93 ms 6312 KB Output is correct
11 Correct 66 ms 6312 KB Output is correct
12 Correct 76 ms 6312 KB Output is correct
13 Correct 66 ms 6312 KB Output is correct
14 Correct 139 ms 6312 KB Output is correct
15 Correct 159 ms 6312 KB Output is correct
16 Correct 143 ms 6312 KB Output is correct
17 Correct 143 ms 6312 KB Output is correct
18 Correct 126 ms 6312 KB Output is correct