Submission #303137

# Submission time Handle Problem Language Result Execution time Memory
303137 2020-09-19T22:59:35 Z tutis Comparing Plants (IOI20_plants) C++17
49 / 100
1736 ms 30200 KB
#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
vector<int>k0, k1;
int K, n;
vector<int>A;
struct ST
{
	int l, r;
	pair<int, int> mn;
	pair<int, int> mn1;
	int del = 0;
	int del1 = 0;
	ST *left, *right;
	ST(int l, int r, vector<int>&a): l(l), r(r)
	{
		if (l < r)
		{
			left = new ST(l, (l + r) / 2, a);
			right = new ST((l + r) / 2 + 1, r, a);
			mn = min(left->mn, right->mn);
		}
		else
			mn = {a[l], l};
		mn1 = mn;
	}
	void fix()
	{
		if (l == r)
		{
			mn.first += del;
			del = 0;
		}
		else
		{
			mn.first += del;
			left->del += del;
			right->del += del;
			del = 0;
		}
	}
	void fix1()
	{
		if (l == r)
		{
			mn1.first += del1;
			del1 = 0;
		}
		else
		{
			mn1.first += del1;
			left->del1 += del1;
			right->del1 += del1;
			del1 = 0;
		}
	}
	void add(int x, int y, int w)
	{
		if (x <= l && r <= y)
		{
			del += w;
			return fix();
		}
		fix();
		if (r < x || y < l)
			return;
		left->add(x, y, w);
		right->add(x, y, w);
		mn = min(left->mn, right->mn);
	}
	void add1(int x, int y, int w)
	{
		if (x <= l && r <= y)
		{
			del1 += w;
			return fix1();
		}
		fix1();
		if (r < x || y < l)
			return;
		left->add1(x, y, w);
		right->add1(x, y, w);
		mn1 = min(left->mn1, right->mn1);
	}
};
void init(int k, vector<int> r)
{
	K = k;
	n = r.size();
	if (k == 2)
	{
		k0 = k1 = vector<int>(n, 0);
		for (int t = 0; t < 2; t++)
			for (int i = n - 1; i >= 0; i--)
			{
				if (r[i] == 0)
					k0[i] = 1 + k0[(i + 1) % n];
				else
					k1[i] = 1 + k1[(i + 1) % n];
			}
		return;
	}
	if (2 * k > n)
	{
		ST medis(0, n - 1, r);
		auto add = [&](int x, int y, int w)
		{
			while (y >= n)
			{
				x -= n;
				y -= n;
			}
			while (x < 0)
			{
				x += n;
				y += n;
			}
			if (y < n)
			{
				medis.add(x, y, w);
			}
			else
			{
				medis.add(x, n - 1, w);
				medis.add(0, y - n, w);
			}
		};
		auto add1 = [&](int x, int y, int w)
		{
			while (y >= n)
			{
				x -= n;
				y -= n;
			}
			while (x < 0)
			{
				x += n;
				y += n;
			}
			if (y < n)
			{
				medis.add1(x, y, w);
			}
			else
			{
				medis.add1(x, n - 1, w);
				medis.add1(0, y - n, w);
			}
		};
		while (medis.mn1.first == 0)
		{
			int i = medis.mn1.second;
			add(i + 1, i + (k - 1), 1);
			add1(i, i, 1);
		}
		A = vector<int>(n, -1);
		for (int tt = 0; tt < n; tt++)
		{
			while (medis.mn1.first == 0)
			{
				int i = medis.mn1.second;
				add(i + 1, i + (k - 1), 1);
				add1(i, i, 1);
			}
			int i = medis.mn.second;
			add(i + 1, i + (k - 1), -1);
			add(i - (k - 1), i - 1, -1);
			add1(i - (k - 1), i - 1, -1);
			A[i] = tt;
			add(i, i, n + 10000);
			add1(i, i, n + 10000);
			r[i] = n + 100;
		}
		return;
	}
	ST medis(0, n - 1, r);
	auto add = [&](int x, int y, int w)
	{
		while (y >= n)
		{
			x -= n;
			y -= n;
		}
		while (x < 0)
		{
			x += n;
			y += n;
		}
		if (y < n)
		{
			medis.add(x, y, w);
		}
		else
		{
			medis.add(x, n - 1, w);
			medis.add(0, y - n, w);
		}
	};
	auto add1 = [&](int x, int y, int w)
	{
		while (y >= n)
		{
			x -= n;
			y -= n;
		}
		while (x < 0)
		{
			x += n;
			y += n;
		}
		if (y < n)
		{
			medis.add1(x, y, w);
		}
		else
		{
			medis.add1(x, n - 1, w);
			medis.add1(0, y - n, w);
		}
	};
	while (medis.mn1.first == 0)
	{
		int i = medis.mn1.second;
		add(i + 1, i + (k - 1), 1);
		add1(i, i, 1);
	}
	A = vector<int>(n, -1);
	int tt = 0;
	while (medis.mn.first == 0)
	{
		tt++;
		while (medis.mn1.first == 0)
		{
			int i = medis.mn1.second;
			add(i + 1, i + (k - 1), 1);
			add1(i, i, 1);
		}
		vector<int>cc;
		while (medis.mn.first == 0)
		{
			int i = medis.mn.second;
			cc.push_back(i);
			add(i, i, n + 10000);
		}
		for (int i : cc)
		{
			add(i + 1, i + (k - 1), -1);
			add(i - (k - 1), i - 1, -1);
			add1(i - (k - 1), i - 1, -1);
			A[i] = tt;
			add(i, i, n + 10000);
			add1(i, i, n + 10000);
			r[i] = n + 100;
		}
	}
}

int compare_plants(int x, int y)
{
	assert(x < y);
	if (K == 2)
	{
		if (k0[x] >= y - x)
			return 1;
		if (k1[x] >= y - x)
			return -1;
		if (k0[y] >= n - y + x)
			return -1;
		if (k1[y] >= n - y + x)
			return 1;
		return 0;
	}
	if (!A.empty())
	{
		if (A[x] == A[y])
			return 0;
		if (A[x] < A[y])
			return 1;
		else
			return -1;
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 64 ms 3192 KB Output is correct
7 Correct 80 ms 3444 KB Output is correct
8 Correct 109 ms 5880 KB Output is correct
9 Correct 108 ms 5752 KB Output is correct
10 Correct 107 ms 5752 KB Output is correct
11 Correct 111 ms 5752 KB Output is correct
12 Correct 105 ms 5752 KB Output is correct
13 Correct 100 ms 5752 KB Output is correct
14 Correct 102 ms 5752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 103 ms 3832 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 6 ms 544 KB Output is correct
10 Correct 91 ms 3832 KB Output is correct
11 Correct 99 ms 3704 KB Output is correct
12 Correct 85 ms 3960 KB Output is correct
13 Correct 88 ms 3832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 103 ms 3832 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 6 ms 544 KB Output is correct
10 Correct 91 ms 3832 KB Output is correct
11 Correct 99 ms 3704 KB Output is correct
12 Correct 85 ms 3960 KB Output is correct
13 Correct 88 ms 3832 KB Output is correct
14 Correct 177 ms 6008 KB Output is correct
15 Correct 1632 ms 30200 KB Output is correct
16 Correct 180 ms 5880 KB Output is correct
17 Correct 1595 ms 30132 KB Output is correct
18 Correct 1032 ms 30072 KB Output is correct
19 Correct 1032 ms 30200 KB Output is correct
20 Correct 1336 ms 30008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 74 ms 3448 KB Output is correct
4 Correct 957 ms 30132 KB Output is correct
5 Correct 1146 ms 30200 KB Output is correct
6 Correct 1523 ms 30136 KB Output is correct
7 Correct 1651 ms 30072 KB Output is correct
8 Correct 1736 ms 30044 KB Output is correct
9 Correct 1027 ms 30200 KB Output is correct
10 Correct 1050 ms 30200 KB Output is correct
11 Correct 99 ms 5880 KB Output is correct
12 Correct 961 ms 30200 KB Output is correct
13 Correct 1141 ms 30200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Incorrect 1 ms 256 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Incorrect 1 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 64 ms 3192 KB Output is correct
7 Correct 80 ms 3444 KB Output is correct
8 Correct 109 ms 5880 KB Output is correct
9 Correct 108 ms 5752 KB Output is correct
10 Correct 107 ms 5752 KB Output is correct
11 Correct 111 ms 5752 KB Output is correct
12 Correct 105 ms 5752 KB Output is correct
13 Correct 100 ms 5752 KB Output is correct
14 Correct 102 ms 5752 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 5 ms 512 KB Output is correct
21 Correct 103 ms 3832 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 6 ms 544 KB Output is correct
24 Correct 91 ms 3832 KB Output is correct
25 Correct 99 ms 3704 KB Output is correct
26 Correct 85 ms 3960 KB Output is correct
27 Correct 88 ms 3832 KB Output is correct
28 Correct 177 ms 6008 KB Output is correct
29 Correct 1632 ms 30200 KB Output is correct
30 Correct 180 ms 5880 KB Output is correct
31 Correct 1595 ms 30132 KB Output is correct
32 Correct 1032 ms 30072 KB Output is correct
33 Correct 1032 ms 30200 KB Output is correct
34 Correct 1336 ms 30008 KB Output is correct
35 Correct 0 ms 256 KB Output is correct
36 Correct 0 ms 256 KB Output is correct
37 Correct 74 ms 3448 KB Output is correct
38 Correct 957 ms 30132 KB Output is correct
39 Correct 1146 ms 30200 KB Output is correct
40 Correct 1523 ms 30136 KB Output is correct
41 Correct 1651 ms 30072 KB Output is correct
42 Correct 1736 ms 30044 KB Output is correct
43 Correct 1027 ms 30200 KB Output is correct
44 Correct 1050 ms 30200 KB Output is correct
45 Correct 99 ms 5880 KB Output is correct
46 Correct 961 ms 30200 KB Output is correct
47 Correct 1141 ms 30200 KB Output is correct
48 Correct 1 ms 256 KB Output is correct
49 Correct 0 ms 256 KB Output is correct
50 Correct 0 ms 256 KB Output is correct
51 Correct 0 ms 256 KB Output is correct
52 Incorrect 1 ms 256 KB Output isn't correct
53 Halted 0 ms 0 KB -