Submission #697200

#TimeUsernameProblemLanguageResultExecution timeMemory
697200allllekssssaSimple game (IZhO17_game)C++14
100 / 100
76 ms6792 KiB
#include<bits/stdc++.h>

using namespace std;

const int maxN = 1e6 + 10;

int bit[maxN];
int n, q;
int a[maxN];

void update(int x, int y) {

	for (int i = x; i < maxN; i+=i&-i) {
		bit[i]+=y;
	}
}

int get(int x) {

	int ans = 0;

	for (int i = x; i > 0; i-=i&-i) {
		ans+=bit[i];
	}

	return ans;
}

void dodaj(int idx, int val) {
	if (idx == 0) return;
	if (idx == n) return;

	int lo = min(a[idx], a[idx + 1]);
	int ro = max(a[idx], a[idx + 1]);

	update(lo, val);
	update(ro + 1, -val);	
}

int main() {

	cin >> n >> q;

	for (int i = 1; i<=n; i++) {
		scanf("%d", &a[i]);
	}

	for (int i = 1; i <= n; i++) {
		dodaj(i, 1);
    }
    
    while(q--) {
    	int tip;

    	scanf("%d", &tip);

    	if (tip == 1) {
    		int pos, h;
    		scanf("%d%d", &pos, &h);
    		dodaj(pos, -1);
    		dodaj(pos - 1, -1);
    		a[pos] = h;
    		dodaj(pos, 1);
    		dodaj(pos -1, 1);
    	} else {
    		int h;
    		scanf("%d", &h);
    		printf("%d\n", get(h));
    	}
    }
}

Compilation message (stderr)

game.cpp: In function 'int main()':
game.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |   scanf("%d", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~
game.cpp:55:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |      scanf("%d", &tip);
      |      ~~~~~^~~~~~~~~~~~
game.cpp:59:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |       scanf("%d%d", &pos, &h);
      |       ~~~~~^~~~~~~~~~~~~~~~~~
game.cpp:67:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |       scanf("%d", &h);
      |       ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...