Submission #703034

# Submission time Handle Problem Language Result Execution time Memory
703034 2023-02-25T16:44:16 Z rainboy Weighting stones (IZhO11_stones) C
100 / 100
44 ms 3640 KB
#include <stdio.h>

#define N_	(1 << 17)

int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }

int sum[N_ * 2], mn[N_ * 2], mx[N_ * 2], n_;

void pul(int i) {
	int l = i << 1, r = l | 1;

	sum[i] = sum[l] + sum[r];
	mn[i] = min(mn[l] + sum[r], mn[r]);
	mx[i] = max(mx[l] + sum[r], mx[r]);
}

void update(int i, int x) {
	i += n_;
	sum[i] = x, mn[i] = min(x, 0), mx[i] = max(x, 0);
	while (i > 1)
		pul(i >>= 1);
}

int main() {
	int n;

	scanf("%d", &n);
	n_ = 1;
	while (n_ < n)
		n_ <<= 1;
	while (n--) {
		int i, s;

		scanf("%d%d", &i, &s), i--;
		update(i, s == 1 ? 1 : -1);
		printf(mn[1] == 0 ? ">\n" : (mx[1] == 0 ? "<\n" : "?\n"));
	}
	return 0;
}

Compilation message

stones.c: In function 'main':
stones.c:28:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
stones.c:35:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |   scanf("%d%d", &i, &s), i--;
      |   ^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 20 ms 2148 KB Output is correct
12 Correct 31 ms 3320 KB Output is correct
13 Correct 34 ms 3564 KB Output is correct
14 Correct 44 ms 3600 KB Output is correct
15 Correct 33 ms 3540 KB Output is correct
16 Correct 33 ms 3564 KB Output is correct
17 Correct 33 ms 3584 KB Output is correct
18 Correct 32 ms 3636 KB Output is correct
19 Correct 36 ms 3608 KB Output is correct
20 Correct 34 ms 3556 KB Output is correct
21 Correct 39 ms 3548 KB Output is correct
22 Correct 36 ms 3536 KB Output is correct
23 Correct 32 ms 3604 KB Output is correct
24 Correct 32 ms 3640 KB Output is correct
25 Correct 33 ms 3588 KB Output is correct