Submission #730938

# Submission time Handle Problem Language Result Execution time Memory
730938 2023-04-26T16:12:13 Z rainboy Monkey and Apple-trees (IZhO12_apple) C
100 / 100
48 ms 4096 KB
#include <stdio.h>

#define N	100000

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

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

int zz[N + 1], ll[N + 1], rr[N + 1], xx[N + 1], yy[N + 1], sz[N + 1], u_, l_, r_;

int node(int x, int y) {
	static int _ = 1;

	zz[_] = rand_();
	xx[_] = x, yy[_] = y, sz[_] = yy[_] - xx[_];
	return _++;
}

void pul(int u) {
	sz[u] = sz[ll[u]] + (yy[u] - xx[u]) + sz[rr[u]];
}

void split_x(int u, int x) {
	if (u == 0) {
		u_ = l_ = r_ = 0;
		return;
	}
	if (xx[u] <= x) {
		split_x(rr[u], x);
		rr[u] = l_, l_ = u;
	} else {
		split_x(ll[u], x);
		ll[u] = r_, r_ = u;
	}
	pul(u);
}

void split_y(int u, int y) {
	if (u == 0) {
		u_ = l_ = r_ = 0;
		return;
	}
	if (yy[u] < y) {
		split_y(rr[u], y);
		rr[u] = l_, l_ = u;
	} else {
		split_y(ll[u], y);
		ll[u] = r_, r_ = u;
	}
	pul(u);
}

int merge(int u, int v) {
	if (u == 0)
		return v;
	if (v == 0)
		return u;
	if (zz[u] < zz[v]) {
		rr[u] = merge(rr[u], v), pul(u);
		return u;
	} else {
		ll[v] = merge(u, ll[v]), pul(v);
		return v;
	}
}

int first(int u) {
	return ll[u] == 0 ? u : first(ll[u]);
}

int last(int u) {
	return rr[u] == 0 ? u : last(rr[u]);
}

int main() {
	int n, c;

	scanf("%d", &n);
	c = 0;
	while (n--) {
		int t, x, y, l, u, r;

		scanf("%d%d%d", &t, &x, &y), x += c, y += c, x--;
		split_y(u_, x), l = l_;
		split_x(r_, y), u = l_, r = r_;
		if (t == 2)
			u = u == 0 ? node(x, y) : node(min(x, xx[first(u)]), max(y, yy[last(u)]));
		else
			printf("%d\n", c = u == 0 ? 0 : sz[u] - max(x - xx[first(u)], 0) - max(yy[last(u)] - y, 0));
		u_ = merge(merge(l, u), r);
	}
	return 0;
}

Compilation message

apple.c: In function 'main':
apple.c:83:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
apple.c:88:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |   scanf("%d%d%d", &t, &x, &y), x += c, y += c, x--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 292 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 4 ms 596 KB Output is correct
5 Correct 5 ms 560 KB Output is correct
6 Correct 4 ms 572 KB Output is correct
7 Correct 4 ms 596 KB Output is correct
8 Correct 19 ms 1924 KB Output is correct
9 Correct 37 ms 3544 KB Output is correct
10 Correct 43 ms 3612 KB Output is correct
11 Correct 39 ms 3528 KB Output is correct
12 Correct 40 ms 3632 KB Output is correct
13 Correct 41 ms 3916 KB Output is correct
14 Correct 40 ms 4000 KB Output is correct
15 Correct 40 ms 4004 KB Output is correct
16 Correct 42 ms 4072 KB Output is correct
17 Correct 48 ms 3996 KB Output is correct
18 Correct 43 ms 3912 KB Output is correct
19 Correct 45 ms 4088 KB Output is correct
20 Correct 43 ms 4096 KB Output is correct