Submission #36252

# Submission time Handle Problem Language Result Execution time Memory
36252 2017-12-06T14:05:12 Z touristk2000 Simple game (IZhO17_game) C++14
22 / 100
173 ms 6788 KB
#include <bits/stdc++.h>

using namespace std;
const int maxn = 1111111;
int n,m;
int a[111111];
int t[maxn];

int sum(int r){
	int res = 0;
	for (; r >= 0; r = (r & (r+1)) - 1)
		res += t[r];
	return res;
}

void inc(int i, int delta){
	for(; i < maxn; i = (i | (i+1)))
		t[i] += delta;
}


int main(){
    //freopen("game.in","r",stdin);
    //freopen("game.out","w",stdout);
    cin >> n >> m;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
        if(i > 1){
            inc(min(a[i - 1],a[i]),  1);
            inc(max(a[i - 1],a[i]), -1);
        }
    }
    for(int i = 0; i < m; i ++){
        int t,p;
        cin >> t >> p;
        if(t == 1){
            int v;
            cin >> v;
            if(p > 1){
                inc(min(a[p - 1], a[p]), -1);
                inc(max(a[p - 1], a[p]),  1);
                inc(min(a[p - 1], v),  1);
                inc(max(a[p - 1], v), -1);
            }
            if(p < n){
                inc(min(a[p + 1], a[p]), -1);
                inc(max(a[p + 1], a[p]),  1);
                inc(min(a[p + 1], v),  1);
                inc(max(a[p + 1], v), -1);
            }
            a[p] = v;
        }
        else{
            cout << sum(p) << endl;
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6788 KB Output is correct
2 Correct 0 ms 6788 KB Output is correct
3 Correct 3 ms 6788 KB Output is correct
4 Correct 0 ms 6788 KB Output is correct
5 Correct 3 ms 6788 KB Output is correct
6 Correct 0 ms 6788 KB Output is correct
7 Correct 6 ms 6788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6788 KB Output is correct
2 Correct 0 ms 6788 KB Output is correct
3 Correct 3 ms 6788 KB Output is correct
4 Correct 0 ms 6788 KB Output is correct
5 Correct 3 ms 6788 KB Output is correct
6 Correct 0 ms 6788 KB Output is correct
7 Correct 6 ms 6788 KB Output is correct
8 Runtime error 173 ms 6788 KB Execution timed out (wall clock limit exceeded)
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6788 KB Output is correct
2 Correct 0 ms 6788 KB Output is correct
3 Correct 3 ms 6788 KB Output is correct
4 Correct 0 ms 6788 KB Output is correct
5 Correct 3 ms 6788 KB Output is correct
6 Correct 0 ms 6788 KB Output is correct
7 Correct 6 ms 6788 KB Output is correct
8 Runtime error 173 ms 6788 KB Execution timed out (wall clock limit exceeded)
9 Halted 0 ms 0 KB -