Submission #38350

# Submission time Handle Problem Language Result Execution time Memory
38350 2018-01-04T03:30:44 Z Talant Simple game (IZhO17_game) C++14
0 / 100
6 ms 37172 KB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair

using namespace std;

typedef long long ll;

const int inf = (int)1e9 + 7;
const int N = (int)1e6 + 7;

int n,m;
int a[N],type,pos,val;
pair<int,int> t[N * 4];

void push (int v) {
        t[v * 2].sc += t[v].sc;
        t[v * 2 + 1].sc += t[v].sc;
        t[v].fr += t[v].sc;
        t[v].sc = 0;
}
void update (int l,int r,int add,int v = 1,int tl = 1,int tr = (N - 6)) {
        if (tl > tr)
                return;
        if (l > tr || tl > r)
                return;

        if (l <= tl && tr <= r) {
                t[v].sc += add;
        }
        else {
                int tm = (tl + tr) >> 1;
                if (l <= tm)
                        update (l,r,add,v * 2,tl,tm);
                if (r >= tm)
                        update (l,r,add,v * 2 + 1,tm + 1,tr);
        }
}
int get (int l,int v = 1,int tl = 1,int tr = (N - 6)) {
        push(v);
        if (tl > tr)
                return 0;
        if (tl == tr)
                return t[v].fr;
        else {
                int tm = (tl + tr) >> 1;
                if (l <= tm)
                        return get(l,v * 2,tl,tm);
                else
                        return get(l,v * 2 + 1,tm + 1,tr);
        }
}
int main () {
        cin >> n >> m;

        for (int i = 1; i <= n; i ++)
                cin >> a[i];

        for (int i = 2; i <= n; i ++) {
                if (a[i - 1] + 1 <= a[i] - 1) {
                        update (a[i - 1] + 1,a[i] - 1,1);
                }
                else if(a[i - 1] - 1 >= a[i] + 1)
                        update (a[i] + 1,a[i - 1] - 1,1);
        }

        for (int i = 1; i <= n; i ++)
                update (a[i],a[i],1);
        while (m --) {
                scanf ("%d", &type);

                if (type == 1) {
                        scanf ("%d%d", &pos,&val);
                        if (pos - 1 > 0) {
                                if (a[pos - 1] + 1 <= a[pos] - 1)
                                        update (a[pos - 1] + 1,a[pos] - 1,-1);
                                else if(a[pos - 1] - 1 >= a[pos] + 1)
                                        update (a[pos] + 1,a[pos - 1] - 1,-1);

                                update (a[pos],a[pos],-1);

                                a[pos] = val;

                                update (a[pos],a[pos],1);

                                if (a[pos - 1] + 1 <= a[pos] - 1)
                                        update (a[pos - 1] + 1,a[pos] - 1,1);
                                else if(a[pos - 1] - 1 >= a[pos] + 1)
                                        update (a[pos] + 1,a[pos - 1] - 1,1);

                        }
                        if (pos + 1 <= n) {
                                pos ++;

                                if (a[pos - 1] + 1 <= a[pos] - 1)
                                        update (a[pos - 1] + 1,a[pos] - 1,-1);
                                else if(a[pos - 1] - 1 >= a[pos] + 1)
                                        update (a[pos] + 1,a[pos - 1] - 1,-1);

                                update (a[pos - 1],a[pos - 1],-1);

                                a[pos - 1] = val;

                                update (a[pos - 1],a[pos - 1],1);

                                if (a[pos - 1] + 1 <= a[pos] - 1)
                                        update (a[pos - 1] + 1,a[pos] - 1,1);
                                else if(a[pos - 1] - 1 >= a[pos] + 1)
                                        update (a[pos] + 1,a[pos - 1] - 1,1);
                        }
                }
                else {
                        scanf ("%d", &val);
                        printf("%d\n", get(val));
                }
        }
}
/**
3 3
1 5 1
2 3
1 1 5
2 3
**/

Compilation message

game.cpp: In function 'int main()':
game.cpp:74:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                 scanf ("%d", &type);
                                    ^
game.cpp:77:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                         scanf ("%d%d", &pos,&val);
                                                  ^
game.cpp:117:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                         scanf ("%d", &val);
                                           ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 37172 KB Output is correct
2 Incorrect 6 ms 37172 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 37172 KB Output is correct
2 Incorrect 6 ms 37172 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 37172 KB Output is correct
2 Incorrect 6 ms 37172 KB Output isn't correct
3 Halted 0 ms 0 KB -