Submission #144198

# Submission time Handle Problem Language Result Execution time Memory
144198 2019-08-16T09:55:12 Z emilem Tenis (COI19_tenis) C++14
51 / 100
500 ms 12352 KB
#include <unordered_set>
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int n;
vector<int> ranking[3], rankAt[3];
vector<bool> canWin;

template<typename T>
						inline bool Maximize(T& a, T rhs)
{
if (rhs <= a)
	return false;
a = rhs;
return true;
}
void Solve()
{
	fill(canWin.begin(), canWin.end(), false);
	vector<int> prefMax[3][3];
	for (int p1 = 0; p1 < 3; ++p1)
		for (int p2 = 0; p2 < 3; ++p2)
			prefMax[p1][p2] = vector<int>(n);
	for (int i = 0; i < n; ++i)
		for (int p1 = 0; p1 < 3; ++p1)
			for (int p2 = 0; p2 < 3; ++p2)
			{
				prefMax[p1][p2][i] = rankAt[p2][ranking[p1][i]];
				if (i)
					Maximize(prefMax[p1][p2][i], prefMax[p1][p2][i - 1]);
			}
	for (int p = 0; p < 3; ++p)
	{
		int maxAt[3] = {-1, -1, -1}; /**/
		unordered_set<int> losers;
		for (int i = 0; i < n; ++i)
		{
			// int maxAt[3];
			for (int p1 = 0; p1 < 3; ++p1)
			{
				int temp = prefMax[p][p1][i];
				if (temp > maxAt[p1])
				{
					for (int j = maxAt[p1] + 1; j <= temp; ++j)
						losers.insert(ranking[p1][j]);
					maxAt[p1] = temp;
				}
			}
			while (true)
			{
				bool noUpdate = true;
				for (int p1 = 0; p1 < 3; ++p1)
					for (int p2 = 0; p2 < 3; ++p2)
					{
						int temp = prefMax[p1][p2][maxAt[p1]];
						if (temp > maxAt[p2])
						{
							for (int j = maxAt[p2] + 1; j <= temp; ++j)
								losers.insert(ranking[p2][j]);
							maxAt[p2] = temp;
							noUpdate = false;
						}
					}
				if (noUpdate)
					break;
			}
			/*
			for (int p1 = 0; p1 < 3; ++p1)
				for (int j = 0; j <= maxAt[p1]; ++j)
					losers.insert(ranking[p1][j]);
			*/
			if (losers.size() == n)
			{
				for (int j = i; j < n; ++j)
				// for (int j = 0; j <= i; ++j)
					canWin[ranking[p][j]] = true;
				break;
			}
		}
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int q;
	cin >> n >> q;
	canWin.resize(n);
	ranking[0] = ranking[1] = ranking[2] = vector<int>(n);
	rankAt[0] = rankAt[1] = rankAt[2] = vector<int>(n);
	for (int p = 0; p < 3; ++p)
		for (int i = n - 1; i >= 0; --i)
		// for (int i = 0; i < n; ++i)
		{
			cin >> ranking[p][i];
			--ranking[p][i];
			rankAt[p][ranking[p][i]] = i;
		}
	// Solve();
	struct Update
	{
		Update(int p_, int a_, int b_)
			: p(p_)
			, a(a_)
			, b(b_)
		{}

		int p, a, b;
	};
	vector<Update> upds;
	bool mustUpdate = true;
	while (q--)
	{
		int type;
		cin >> type;
		if (type == 1)
		{
			if (mustUpdate)
			{
				for (auto upd = upds.begin(); upd != upds.end(); ++upd)
				{
					swap(ranking[upd->p][rankAt[upd->p][upd->a]], ranking[upd->p][rankAt[upd->p][upd->b]]);
					swap(rankAt[upd->p][upd->a], rankAt[upd->p][upd->b]);
					/*
					for (int p = 0; p < 3; ++p)
						for (int i = n - 1; i >= 0; --i)
							rankAt[p][ranking[p][i]] = i;
					*/
				}
				Solve();
				upds.clear();
				mustUpdate = false;
			}
			int nephew;
			cin >> nephew; --nephew;
			cout << (canWin[nephew] ? "DA\n" : "NE\n");
		}
		else
		{
			int p, a, b;
			cin >> p >> a >> b; --p; --a; --b;
			upds.push_back(Update(p, a, b));
			mustUpdate = true;
			/*
			swap(ranking[p][rankAt[p][a]], ranking[p][rankAt[p][b]]);
			for (int p = 0; p < 3; ++p)
				for (int i = n - 1; i >= 0; --i)
					rankAt[p][ranking[p][i]] = i;
			Solve();
			*/
		}
	}

	char I;
	cin >> I;
}

Compilation message

tenis.cpp: In function 'void Solve()':
tenis.cpp:74:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (losers.size() == n)
        ~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 1 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 1 ms 404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 1 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 1 ms 404 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 1 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 1 ms 404 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 306 ms 10304 KB Output is correct
14 Correct 287 ms 12076 KB Output is correct
15 Correct 325 ms 11960 KB Output is correct
16 Correct 129 ms 11912 KB Output is correct
17 Correct 238 ms 11920 KB Output is correct
18 Correct 137 ms 11960 KB Output is correct
19 Correct 229 ms 12104 KB Output is correct
20 Correct 39 ms 4472 KB Output is correct
21 Correct 253 ms 11960 KB Output is correct
22 Correct 137 ms 11960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 148 ms 10248 KB Output is correct
2 Correct 157 ms 10248 KB Output is correct
3 Correct 158 ms 10340 KB Output is correct
4 Correct 153 ms 10248 KB Output is correct
5 Correct 155 ms 10296 KB Output is correct
6 Correct 158 ms 10248 KB Output is correct
7 Correct 163 ms 10200 KB Output is correct
8 Correct 175 ms 10248 KB Output is correct
9 Correct 153 ms 10256 KB Output is correct
10 Correct 152 ms 10188 KB Output is correct
11 Correct 153 ms 10268 KB Output is correct
12 Correct 155 ms 10128 KB Output is correct
13 Correct 152 ms 10236 KB Output is correct
14 Correct 161 ms 10228 KB Output is correct
15 Correct 151 ms 10256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 1 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 1 ms 404 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 306 ms 10304 KB Output is correct
14 Correct 287 ms 12076 KB Output is correct
15 Correct 325 ms 11960 KB Output is correct
16 Correct 129 ms 11912 KB Output is correct
17 Correct 238 ms 11920 KB Output is correct
18 Correct 137 ms 11960 KB Output is correct
19 Correct 229 ms 12104 KB Output is correct
20 Correct 39 ms 4472 KB Output is correct
21 Correct 253 ms 11960 KB Output is correct
22 Correct 137 ms 11960 KB Output is correct
23 Correct 148 ms 10248 KB Output is correct
24 Correct 157 ms 10248 KB Output is correct
25 Correct 158 ms 10340 KB Output is correct
26 Correct 153 ms 10248 KB Output is correct
27 Correct 155 ms 10296 KB Output is correct
28 Correct 158 ms 10248 KB Output is correct
29 Correct 163 ms 10200 KB Output is correct
30 Correct 175 ms 10248 KB Output is correct
31 Correct 153 ms 10256 KB Output is correct
32 Correct 152 ms 10188 KB Output is correct
33 Correct 153 ms 10268 KB Output is correct
34 Correct 155 ms 10128 KB Output is correct
35 Correct 152 ms 10236 KB Output is correct
36 Correct 161 ms 10228 KB Output is correct
37 Correct 151 ms 10256 KB Output is correct
38 Execution timed out 1065 ms 12352 KB Time limit exceeded
39 Halted 0 ms 0 KB -