Submission #36251

#TimeUsernameProblemLanguageResultExecution timeMemory
36251touristk2000Simple game (IZhO17_game)C++14
100 / 100
506 ms41076 KiB
#include <bits/stdc++.h>
#define N 1111111
#define debug(x) cout << #x <<  ' ' << x << endl;
using namespace std;
int t[N << 2], tt[N << 2];
void push (int v) {
	if (tt[v]){
		t[v*2] += tt[v];
		t[v*2+1] += tt[v];
		tt[v << 1] += tt[v];
		tt[v << 1 | 1] += tt[v];
		tt[v] = 0;
	}
}
void update (int v, int tl, int tr, int l, int r, int color) {
	if (l > r)
		return;
	if (l == tl && tr == r){
		t[v] += color;
		tt[v] += color;
	}
	else {
		push (v);
		int tm = (tl + tr) / 2;
		update (v*2, tl, tm, l, min(r,tm), color);
		update (v*2+1, tm+1, tr, max(l,tm+1), r, color);
		t[v] = t[v << 1] + t[v << 1 | 1];
	}
}
 
int get (int v, int tl, int tr, int pos) {
	if (tl == tr)
		return t[v];
	push (v);
	int tm = (tl + tr) / 2;
	if (pos <= tm)
		return get (v*2, tl, tm, pos);
	else
		return get (v*2+1, tm+1, tr, pos);
}
int n, a[N], m;
int main(){
    //freopen("game.in","r",stdin);
    //freopen("game.out","w",stdout);
    scanf("%d%d%d", &n, &m, &a[1]);
    for(int i = 2; i <= n; i ++){
        scanf("%d", a + i);
        update(1, 1, N, min(a[i - 1], a[i]), max(a[i - 1], a[i]), 1);
    }
    while(m --){
        int t, p;
        scanf("%d%d",&t,&p);
        if(t == 1){
            int v;
            scanf("%d", &v);
            if(p > 1){
                update(1, 1, N, min(a[p - 1], a[p]), max(a[p - 1], a[p]), -1);
                update(1, 1, N, min(a[p - 1], v), max(a[p - 1], v), 1);
            }
            if(p < n){
                update(1, 1, N, min(a[p + 1], a[p]), max(a[p + 1], a[p]), -1);
                update(1, 1, N, min(a[p + 1], v), max(a[p + 1], v), 1);
            }
            a[p] = v;
        }
        else
            printf("%d\n", get(1, 1, N, p));
    }
    return 0;
}

Compilation message (stderr)

game.cpp: In function 'int main()':
game.cpp:45:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &n, &m, &a[1]);
                                   ^
game.cpp:47:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", a + i);
                           ^
game.cpp:52:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&t,&p);
                            ^
game.cpp:55:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &v);
                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...