結果

問題 No.961 Vibrant Fillumination
ユーザー square1001square1001
提出日時 2020-01-18 00:38:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,735 bytes
コンパイル時間 2,641 ms
コンパイル使用メモリ 107,664 KB
実行使用メモリ 814,404 KB
最終ジャッジ日時 2023-09-08 10:12:42
合計ジャッジ時間 24,773 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1,494 ms
381,964 KB
testcase_03 AC 1,350 ms
384,308 KB
testcase_04 AC 1,416 ms
381,980 KB
testcase_05 AC 1,384 ms
386,620 KB
testcase_06 AC 1,394 ms
381,948 KB
testcase_07 AC 1,391 ms
382,188 KB
testcase_08 AC 1,403 ms
386,324 KB
testcase_09 AC 1,399 ms
384,544 KB
testcase_10 WA -
testcase_11 MLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<long long> H(N);
	for (int i = 0; i < N; ++i) cin >> H[i];
	vector<int> A(N), B(N), C(N), D(N), E(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i] >> B[i] >> C[i] >> D[i] >> E[i];
		--E[i];
	}
	vector<vector<int> > G(N);
	for (int i = 0; i < N; ++i) {
		G[E[i]].push_back(i);
	}
	vector<int> perm(N);
	int active = 0;
	for (int i = 0; i < N; ++i) {
		perm[i] = i;
		if (!G[i].empty()) ++active;
	}
	sort(perm.begin(), perm.end(), [&](int i, int j) { return G[i].size() > G[j].size(); });
	int threshold = int(sqrt(N));
	int lp = 0, sum = 0, cols = 0;
	vector<vector<int> > group;
	vector<int> col;
	for (int i = 0; i < active; ++i) {
		sum += G[perm[i]].size();
		if (sum >= threshold || i == active - 1) {
			if (lp == i) {
				int divs = max(int(G[perm[i]].size()) / threshold, 1);
				for (int j = 0; j < divs; ++j) {
					int dl = j * G[perm[i]].size() / divs, dr = (j + 1) * G[perm[i]].size() / divs;
					group.push_back(vector<int>(G[perm[i]].begin() + dl, G[perm[i]].begin() + dr));
					col.push_back(cols);
				}
			}
			else {
				group.push_back(vector<int>());
				for (int j = lp; j <= i; ++j) {
					group.back().insert(group.back().end(), G[j].begin(), G[j].end());
				}
				col.push_back(cols);
			}
			sum = 0, lp = i + 1;
			++cols;
		}
	}
	vector<vector<int> > cpx, cpy; vector<vector<vector<long long> > > dat;
	for (int i = 0; i < group.size(); ++i) {
		vector<int> cps, cx = { 0, 2 * N }, cy = { 0, 2 * N };
		for (int j : group[i]) {
			cps.push_back(E[j]);
			cx.push_back(A[j]);
			cx.push_back(C[j]);
			cy.push_back(B[j]);
			cy.push_back(D[j]);
		}
		sort(cx.begin(), cx.end());
		cx.erase(unique(cx.begin(), cx.end()), cx.end());
		sort(cy.begin(), cy.end());
		cy.erase(unique(cy.begin(), cy.end()), cy.end());
		cpx.push_back(cx);
		cpy.push_back(cy);
		sort(cps.begin(), cps.end());
		cps.erase(unique(cps.begin(), cps.end()), cps.end());
		vector<vector<int> > F(cps.size());
		for (int j : group[i]) {
			F[lower_bound(cps.begin(), cps.end(), E[j]) - cps.begin()].push_back(j);
		}
		int h = cx.size(), w = cy.size();
		vector<vector<long long> > subdat(h + 1, vector<long long>(w + 1));
		for (int j = 0; j < F.size(); ++j) {
			vector<int> csx, csy;
			for (int k : F[j]) {
				csx.push_back(A[k]);
				csx.push_back(C[k]);
				csy.push_back(B[k]);
				csy.push_back(D[k]);
			}
			sort(csx.begin(), csx.end());
			csx.erase(unique(csx.begin(), csx.end()), csx.end());
			sort(csy.begin(), csy.end());
			csy.erase(unique(csy.begin(), csy.end()), csy.end());
			vector<vector<int> > imos(csx.size(), vector<int>(csy.size()));
			for (int k : F[j]) {
				int xa = lower_bound(csx.begin(), csx.end(), A[k]) - csx.begin();
				int ya = lower_bound(csy.begin(), csy.end(), B[k]) - csy.begin();
				int xb = lower_bound(csx.begin(), csx.end(), C[k]) - csx.begin();
				int yb = lower_bound(csy.begin(), csy.end(), D[k]) - csy.begin();
				++imos[xa][ya];
				++imos[xb][yb];
				--imos[xa][yb];
				--imos[xb][ya];
			}
			for (int k = 1; k < csx.size(); ++k) {
				for (int l = 0; l < csy.size(); ++l) {
					imos[k][l] += imos[k - 1][l];
				}
			}
			for (int k = 0; k < csx.size(); ++k) {
				for (int l = 1; l < csy.size(); ++l) {
					imos[k][l] += imos[k][l - 1];
				}
			}
			for (int k = 0; k < csx.size(); ++k) {
				csx[k] = lower_bound(cx.begin(), cx.end(), csx[k]) - cx.begin();
			}
			for (int k = 0; k < csy.size(); ++k) {
				csy[k] = lower_bound(cy.begin(), cy.end(), csy[k]) - cy.begin();
			}
			for (int k = 0; k < csx.size() - 1; ++k) {
				for (int l = 0; l < csy.size() - 1; ++l) {
					if (imos[k][l] == 0) continue;
					subdat[csx[k]][csy[l]] ^= H[cps[j]];
					subdat[csx[k + 1]][csy[l + 1]] ^= H[cps[j]];
					subdat[csx[k]][csy[l + 1]] ^= H[cps[j]];
					subdat[csx[k + 1]][csy[l]] ^= H[cps[j]];
				}
			}
		}
		for (int j = 1; j < cx.size(); ++j) {
			for (int k = 0; k < cy.size(); ++k) {
				subdat[j][k] ^= subdat[j - 1][k];
			}
		}
		for (int j = 0; j < cx.size(); ++j) {
			for (int k = 1; k < cy.size(); ++k) {
				subdat[j][k] ^= subdat[j][k - 1];
			}
		}
		dat.push_back(subdat);
	}
	int Q;
	cin >> Q;
	while (Q--) {
		int x, y;
		cin >> x >> y;
		vector<long long> sub(cols);
		for (int i = 0; i < group.size(); ++i) {
			if (sub[col[i]] != 0) continue;
			int px = lower_bound(cpx[i].begin(), cpx[i].end(), x + 1) - cpx[i].begin() - 1;
			int py = lower_bound(cpy[i].begin(), cpy[i].end(), y + 1) - cpy[i].begin() - 1;
			sub[col[i]] = dat[i][px][py];
		}
		long long ans = 0;
		for (int i = 0; i < cols; ++i) {
			ans ^= sub[i];
		}
		cout << ans << '\n';
	}
	return 0;
}
0