QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#668799#5113. Bridgehei_yu_baiRE 0ms3532kbC++202.4kb2024-10-23 16:00:062024-10-23 16:00:11

Judging History

你现在查看的是最新测评结果

  • [2024-10-23 16:00:11]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3532kb
  • [2024-10-23 16:00:06]
  • 提交

answer

#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
#include<cmath>
#include<numeric>

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, m, q;
	cin >> n >> m >> q;

	int s = sqrt(q);

	vector<pair<int, int>> query;
	vector<vector<pair<int, int>>> swaps(m + 2);
	vector<int> inclu, cur(n + 1), vis(n + 1), pos(n + 1), tpos(n + 1), a(s), b(s);
	vector<vector<int>> link(q + 1, vector<int>(n + 1));

	vector<int> ans(q);
	int tot = 0;

	for (int i = 0; i < (q + s - 1) / s; ++i) {
		query.clear(), inclu.clear();;
		for (int j = 1; j <= n; ++j) cur[j] = j, vis[j] = false;
		for (int j = i * s; j < min(q, (i + 1) * s); ++j) {
			int op, x, y;
			cin >> op >> x;
			if (op == 1) {
				cin >> y;
				swaps[y].emplace_back(j, x);
			}
			else {
				query.emplace_back(j, x);
				inclu.emplace_back(x);
				vis[x] = true;
			}
		}

		//cout << "-1\n";

		for (int j = 1; j <= m; ++j) {
			for (auto o : swaps[j]) {
				int& x = cur[o.second], & y = cur[o.second + 1];
				swap(x, y);

				if (o.first / s == i) {
					if (!vis[x]) {
						vis[x] = true;
						inclu.emplace_back(x);
					}
					if (!vis[y]) {
						vis[y] = true;
						inclu.emplace_back(y);
					}
				}
			}
		}

		//cout << "-1\n";

		int len = 0, cnt = inclu.size();

		for (int j = 1; j <= n; ++j) cur[j] = j, pos[j] = j;
		for (int j = 0; j < cnt; ++j) tpos[j] = pos[inclu[j]];

		for (int j = 1; j <= m; ++j) {
			for (auto o : swaps[j]) {
				int& x = cur[o.second], & y = cur[o.second + 1];
				if (o.first / s == i) {
					for (int k = 0; k < cnt; ++k) {
						link[len][tpos[k]] = pos[inclu[k]];
					}
					a[len] = o.first, b[len] = o.second;
					++len;
				}

				swap(x, y);
				swap(pos[x], pos[y]);

				if(o.first / s== i)
					for (int k = 0; k < cnt; ++k) {
						tpos[k] = pos[inclu[k]];
					}
			}
		}

		for (int k = 0; k < cnt; ++k) {
			link[len][tpos[k]] = pos[inclu[k]];
		}
		a[len] = 1e9;
		len++;

		//cout << "-1\n";


		for (auto o : query) {
			int t = o.first, p = o.second;
			for (int j = 0; j < len; ++j) {
				p = link[j][p];
				if (a[j] < t) {
					if (b[j] == p) p++;
					else if (b[j] == p - 1) p--;
				}
			}

			ans[tot++] = p;
			//cout << p << "\n";
		}

		//cout << "-1\n";

	}


	for (int i = 0; i < tot; ++i) cout << ans[i] << "\n";
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3532kb

input:

3 4 13
2 2
1 1 3
2 1
2 2
2 3
1 2 4
2 1
2 2
2 3
1 2 1
2 1
2 2
2 3

output:

2
2
1
3
3
1
2
3
2
1

result:

ok 10 numbers

Test #2:

score: -100
Runtime Error

input:

3 100000 99997
2 2
2 2
2 3
2 3
2 3
2 3
2 3
1 2 11047
1 1 98732
1 2 90045
1 1 43556
2 1
2 3
1 2 17242
1 1 17027
2 1
1 1 94195
2 1
2 2
2 1
2 3
1 1 34124
1 2 14354
1 2 673
1 2 39812
1 2 35520
1 2 16046
2 3
2 2
1 1 25410
2 3
2 1
2 3
2 2
1 2 55684
2 1
1 2 24811
1 2 92268
1 2 60268
2 2
1 1 89272
1 2 19232...

output:

2
2
2
2
3
3
3
2
3
2
2
1
2
3
3
1
3
2
3
1
2
1
1
2
1
3
2
2
1
3
3
2
3
3
2
1
3
2
1
3
2
1
1
2
2
1
3
3
2
3
1
3
2
2
3
3
2
1
2
1
2
3
2
3
2
2
2
2
1
3
1
3
2
1
2
2
2
1
1
1
2
3
1
3
3
2
2
2
3
3
1
2
2
3
2
2
1
1
2
3
2
3
2
1
1
3
1
2
1
1
2
1
1
2
2
3
1
3
1
3
3
1
1
2
1
1
2
2
1
3
2
2
2
1
3
3
3
3
1
3
3
1
3
1
3
1
3
1
3
1
...

result: