답안 #382630

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
382630 2021-03-27T23:02:03 Z rainboy 가로등 (APIO19_street_lamps) C
60 / 100
223 ms 7020 KB
#include <stdio.h>
#include <string.h>

#define N	300000
#define Q	300000
#define N_	(1 << 19)
#define S	100

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

int st[N_ * 2], n_;

void build(int n) {
	n_ = 1;
	while (n_ < n)
		n_ <<= 1;
	memset(st, 0x3f, n_ * 2 * sizeof *st);
}

void pul(int i) {
	st[i] = max(st[i << 1 | 0], st[i << 1 | 1]);
}

void update(int i, int x) {
	st[i += n_] = x;
	while (i > 1)
		pul(i >>= 1);
}

int query(int l, int r) {
	int x = -1;

	for (l += n_, r += n_; l <= r; l >>= 1, r >>= 1) {
		if ((l & 1) == 1)
			x = max(x, st[l++]);
		if ((r & 1) == 0)
			x = max(x, st[r--]);
	}
	return x;
}

int main() {
	static char cc[N + 1];
	static int ll[S][S], ans[N];
	int n, q, h, h_, i;

	scanf("%d%d%s", &n, &q, cc);
	if (n <= 100 && q <= 100) {
		for (h = 0; h < q; h++) {
			static char s[8];

			scanf("%s", s);
			for (i = 0; i < n; i++)
				ll[h][i] = cc[i] == '0' ? i + 1 : (i == 0 ? 0 : ll[h][i - 1]);
			if (s[0] == 't') {
				scanf("%d", &i), i--;
				cc[i] = (cc[i] - '0' ^ 1) + '0';
			} else {
				int l, r, cnt;

				scanf("%d%d", &l, &r), l--, r -= 2;
				cnt = 0;
				for (h_ = 0; h_ <= h; h_++)
					if (ll[h_][r] <= l)
						cnt++;
				printf("%d\n", cnt);
			}
		}
	} else {
		build(n);
		for (i = 0; i < n; i++)
			if (cc[i] == '1')
				update(i, 0);
		for (h = 1; h <= q; h++) {
			static char s[8];

			scanf("%s", s);
			if (s[0] == 't') {
				scanf("%d", &i), i--;
				update(i, h);
				if (cc[i] == '0')
					cc[i] = '1', ans[i] -= h;
				else
					cc[i] = '0', ans[i] += h;
			} else {
				int l, r;

				scanf("%d%d", &l, &r), l--, r -= 2;
				if (l == r)
					printf("%d\n", ans[l] + (cc[l] == '0' ? 0 : h));
				else
					printf("%d\n", max(h - query(l, r), 0));
			}
		}
	}
	return 0;
}

Compilation message

street_lamps.c: In function 'main':
street_lamps.c:57:20: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   57 |     cc[i] = (cc[i] - '0' ^ 1) + '0';
      |              ~~~~~~^~~~~
street_lamps.c:47:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   47 |  scanf("%d%d%s", &n, &q, cc);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
street_lamps.c:52:4: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   52 |    scanf("%s", s);
      |    ^~~~~~~~~~~~~~
street_lamps.c:56:5: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   56 |     scanf("%d", &i), i--;
      |     ^~~~~~~~~~~~~~~
street_lamps.c:61:5: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   61 |     scanf("%d%d", &l, &r), l--, r -= 2;
      |     ^~~~~~~~~~~~~~~~~~~~~
street_lamps.c:77:4: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   77 |    scanf("%s", s);
      |    ^~~~~~~~~~~~~~
street_lamps.c:79:5: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   79 |     scanf("%d", &i), i--;
      |     ^~~~~~~~~~~~~~~
street_lamps.c:88:5: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   88 |     scanf("%d%d", &l, &r), l--, r -= 2;
      |     ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 1260 KB Output is correct
2 Correct 102 ms 1260 KB Output is correct
3 Correct 106 ms 1388 KB Output is correct
4 Correct 178 ms 6668 KB Output is correct
5 Correct 169 ms 7020 KB Output is correct
6 Correct 137 ms 6508 KB Output is correct
7 Correct 141 ms 5356 KB Output is correct
8 Correct 159 ms 6764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 116 ms 6124 KB Output is correct
6 Correct 143 ms 5996 KB Output is correct
7 Correct 181 ms 6252 KB Output is correct
8 Correct 215 ms 6764 KB Output is correct
9 Correct 107 ms 1080 KB Output is correct
10 Correct 112 ms 1388 KB Output is correct
11 Correct 112 ms 1388 KB Output is correct
12 Correct 223 ms 5612 KB Output is correct
13 Correct 207 ms 6764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 96 ms 1260 KB Output is correct
9 Correct 102 ms 1260 KB Output is correct
10 Correct 106 ms 1388 KB Output is correct
11 Correct 178 ms 6668 KB Output is correct
12 Correct 169 ms 7020 KB Output is correct
13 Correct 137 ms 6508 KB Output is correct
14 Correct 141 ms 5356 KB Output is correct
15 Correct 159 ms 6764 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 116 ms 6124 KB Output is correct
21 Correct 143 ms 5996 KB Output is correct
22 Correct 181 ms 6252 KB Output is correct
23 Correct 215 ms 6764 KB Output is correct
24 Correct 107 ms 1080 KB Output is correct
25 Correct 112 ms 1388 KB Output is correct
26 Correct 112 ms 1388 KB Output is correct
27 Correct 223 ms 5612 KB Output is correct
28 Correct 207 ms 6764 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Incorrect 1 ms 364 KB Output isn't correct
31 Halted 0 ms 0 KB -