Submission #382627

# Submission time Handle Problem Language Result Execution time Memory
382627 2021-03-27T22:56:58 Z rainboy Street Lamps (APIO19_street_lamps) C
20 / 100
5000 ms 384 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) {
	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) == 0)
			x = max(x, st[l++]);
		if ((r & 1) == 1)
			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 (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 (r - l == 1)
					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:56:20: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   56 |     cc[i] = (cc[i] - '0' ^ 1) + '0';
      |              ~~~~~~^~~~~
street_lamps.c:46:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   46 |  scanf("%d%d%s", &n, &q, cc);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
street_lamps.c:51:4: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   51 |    scanf("%s", s);
      |    ^~~~~~~~~~~~~~
street_lamps.c:55:5: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   55 |     scanf("%d", &i), i--;
      |     ^~~~~~~~~~~~~~~
street_lamps.c:60:5: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   60 |     scanf("%d%d", &l, &r), l--, r -= 2;
      |     ^~~~~~~~~~~~~~~~~~~~~
street_lamps.c:73:4: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   73 |    scanf("%s", s);
      |    ^~~~~~~~~~~~~~
street_lamps.c:75:5: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   75 |     scanf("%d", &i), i--;
      |     ^~~~~~~~~~~~~~~
street_lamps.c:84:5: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   84 |     scanf("%d%d", &l, &r), l--, r -= 2;
      |     ^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 376 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
# Verdict Execution time Memory Grader output
1 Execution timed out 5016 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5050 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5040 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 376 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 Execution timed out 5016 ms 364 KB Time limit exceeded
9 Halted 0 ms 0 KB -