Submission #411196

# Submission time Handle Problem Language Result Execution time Memory
411196 2021-05-24T15:47:25 Z two_sides Comparing Plants (IOI20_plants) C++17
5 / 100
301 ms 49560 KB
#include "plants.h"
#include <bits/stdc++.h>

using namespace std;

struct segment_tree {
	int l, r, m, v, t;
	segment_tree *c[2];

	segment_tree(int l, int r,
	const vector <int> &a):
	l(l), r(r), m((l + r) / 2), t(0) {
		if (l + 1 == r) {
			v = a[l]; return;
		}
		c[0] = new segment_tree(l, m, a);
		c[1] = new segment_tree(m, r, a);
		pull();
	}

	void apply(int x) {
		v -= x; t -= x;
	}

	void pull() {
		v = min(c[0]->v, c[1]->v);
	}

	void push() {
		c[0]->apply(t);
		c[1]->apply(t); t = 0;
	}

	void dec(int x, int y) {
		if (x == y) return;
		if (l >= x && r <= y)
			return	apply(1);
		push();
		if (m > x) c[0]->dec(x, y);
		if (m < y) c[1]->dec(x, y);
		pull();
	}

	void del(int p) {
		if (l + 1 == r) v = 1e9;
		else {
			push();
			if (m > p) c[0]->del(p);
			else c[1]->del(p);
			pull();
		}
	}

	int zero() {
		if (l + 1 == r) return l;
		if (!c[0]->v)
			return c[0]->zero();
		return c[1]->zero();
	}
};

void build(int k, vector <int> r,
vector <int> &idx, vector <int> &ptr) {
	int n = r.size();
	ptr.resize(n + 1);
	idx.resize(n + 1);
	vector <int> que(n + 1);
	que[0] = n; idx[n] = -1;
	int first = 1, last = 1;
	segment_tree seg(0, n, r);
	for (int i = 0, p; i < n; i++) {
		while (seg.v) {
			p = que[first++];
			seg.dec(p - k + n + 1, n);
		}
		p = seg.zero(); idx[p] = i;
		seg.del(p);
		if (p < k - 1)
			seg.dec(0, que[last++] = p);
		else seg.dec(p - k + 1, p);
		ptr[p] = idx[que[first - 1]];
	}
}

vector <int> idxg, idxl;
vector <int> ptrg, ptrl;

void init(int k, vector <int> r) {
	build(k, r, idxg, ptrg);
	for (int &x : r) x = k - 1 - x;
	build(k, r, idxl, ptrl);
	return;
}

int compare_plants(int x, int y) {
	if (x > y)
		return -compare_plants(y, x);
	if (idxg[x] > idxg[y] ||
	ptrl[y] >= idxl[x]) return -1;
	if (idxl[x] > idxl[y] ||
	ptrg[y] >= idxg[x]) return 1;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 284 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 60 ms 4036 KB Output is correct
7 Correct 87 ms 9664 KB Output is correct
8 Correct 300 ms 49392 KB Output is correct
9 Correct 296 ms 49328 KB Output is correct
10 Correct 300 ms 49304 KB Output is correct
11 Correct 295 ms 49392 KB Output is correct
12 Correct 301 ms 49316 KB Output is correct
13 Correct 298 ms 49452 KB Output is correct
14 Correct 298 ms 49560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Incorrect 1 ms 288 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Incorrect 1 ms 288 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Runtime error 1 ms 292 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Runtime error 1 ms 332 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 284 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 60 ms 4036 KB Output is correct
7 Correct 87 ms 9664 KB Output is correct
8 Correct 300 ms 49392 KB Output is correct
9 Correct 296 ms 49328 KB Output is correct
10 Correct 300 ms 49304 KB Output is correct
11 Correct 295 ms 49392 KB Output is correct
12 Correct 301 ms 49316 KB Output is correct
13 Correct 298 ms 49452 KB Output is correct
14 Correct 298 ms 49560 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Incorrect 1 ms 288 KB Output isn't correct
18 Halted 0 ms 0 KB -