Submission #697200

# Submission time Handle Problem Language Result Execution time Memory
697200 2023-02-08T20:51:17 Z allllekssssa Simple game (IZhO17_game) C++14
100 / 100
76 ms 6792 KB
#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

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 time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3668 KB Output is correct
6 Correct 3 ms 3796 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3668 KB Output is correct
6 Correct 3 ms 3796 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 40 ms 1628 KB Output is correct
9 Correct 50 ms 6760 KB Output is correct
10 Correct 45 ms 6776 KB Output is correct
11 Correct 45 ms 1616 KB Output is correct
12 Correct 41 ms 2772 KB Output is correct
13 Correct 46 ms 2748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3668 KB Output is correct
6 Correct 3 ms 3796 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 40 ms 1628 KB Output is correct
9 Correct 50 ms 6760 KB Output is correct
10 Correct 45 ms 6776 KB Output is correct
11 Correct 45 ms 1616 KB Output is correct
12 Correct 41 ms 2772 KB Output is correct
13 Correct 46 ms 2748 KB Output is correct
14 Correct 76 ms 6712 KB Output is correct
15 Correct 59 ms 6760 KB Output is correct
16 Correct 56 ms 6752 KB Output is correct
17 Correct 54 ms 6776 KB Output is correct
18 Correct 59 ms 6792 KB Output is correct