QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#668795#5113. Bridgehei_yu_baiCompile Error//C++202.3kb2024-10-23 15:59:052024-10-23 15:59:13

Judging History

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

  • [2024-10-23 15:59:13]
  • 评测
  • [2024-10-23 15:59:05]
  • 提交

answer

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

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;
}

詳細信息

answer.code: In function ‘int main()’:
answer.code:13:17: error: ‘sqrt’ was not declared in this scope
   13 |         int s = sqrt(q);
      |                 ^~~~