結果
| 問題 |
No.961 Vibrant Fillumination
|
| コンテスト | |
| ユーザー |
emthrm
|
| 提出日時 | 2020-02-25 23:58:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 601 ms / 5,000 ms |
| コード長 | 4,758 bytes |
| コンパイル時間 | 3,439 ms |
| コンパイル使用メモリ | 213,284 KB |
| 最終ジャッジ日時 | 2025-01-09 02:14:03 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 48 |
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
IOSetup() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
}
} iosetup;
int main() {
int n; cin >> n;
vector<ll> h(n); REP(i, n) cin >> h[i];
vector<int> a(n), b(n), c(n), d(n), e(n);
vector<pair<int, int> > xs, ys;
REP(i, n) {
cin >> a[i] >> b[i] >> c[i] >> d[i] >> e[i]; --e[i];
xs.emplace_back(a[i], i);
xs.emplace_back(c[i], n + i);
ys.emplace_back(b[i], i);
ys.emplace_back(d[i], n + i);
}
int Q; cin >> Q;
vector<int> p(Q), q(Q);
REP(i, Q) {
cin >> p[i] >> q[i];
xs.emplace_back(p[i], n * 2 + i);
ys.emplace_back(q[i], n * 2 + i);
}
sort(ALL(xs));
int X = 0;
for (pair<int, int> pr : xs) {
if (pr.second >= n * 2) {
p[pr.second - n * 2] = X - 1;
} else {
if (pr.second < n) {
a[pr.second] = X;
} else {
c[pr.second - n] = X;
}
++X;
}
}
++X;
vector<int> in_x(X, -1), out_x(X, -1);
REP(i, n) {
in_x[a[i]] = i;
out_x[c[i]] = i;
// cout << 'x' << i << " [" << a[i] << ',' << c[i] << "]\n";
}
// REP(i, X) cout << in_x[i] << " \n"[i + 1 == X];
// REP(i, X) cout << out_x[i] << " \n"[i + 1 == X];
sort(ALL(ys));
int Y = 0;
for (pair<int, int> pr : ys) {
if (pr.second >= n * 2) {
q[pr.second - n * 2] = Y - 1;
} else {
if (pr.second < n) {
b[pr.second] = Y;
} else {
d[pr.second - n] = Y;
}
++Y;
}
}
++Y;
vector<int> in_y(Y, -1), out_y(Y, -1);
REP(i, n) {
in_y[b[i]] = i;
out_y[d[i]] = i;
// cout << 'y' << i << " [" << b[i] << ',' << d[i] << "]\n";
}
int B = sqrt(X), m = (X + B - 1) / B;
vector<vector<int> > query(m);
REP(i, Q) {
if (p[i] != -1 && q[i] != -1) query[p[i] / B].emplace_back(i);
// cout << p[i] << ' ' << q[i] << '\n';
}
vector<ll> ans(Q, 0);
REP(block, m) {
sort(ALL(query[block]), [&](int l, int r) { return q[l] < q[r]; });
ll hash = 0;
vector<int> cnt(n, 0);
int x = block * B, y = 0;
for (int idx : query[block]) {
for (; y <= q[idx]; ++y) {
if (in_y[y] != -1) {
int film = in_y[y];
if (a[film] < x && x <= c[film]) {
if (cnt[e[film]] == 0) hash ^= h[e[film]];
++cnt[e[film]];
}
}
if (out_y[y] != -1) {
int film = out_y[y];
if (a[film] < x && x <= c[film]) {
--cnt[e[film]];
if (cnt[e[film]] == 0) hash ^= h[e[film]];
}
}
// cout << '(' << x << ',' << y << ") ";
// REP(i, n) cout << cnt[i] << " \n"[i + 1 == n];
}
for (; x <= p[idx]; ++x) {
if (in_x[x] != -1) {
int film = in_x[x];
if (b[film] < y && y <= d[film]) {
if (cnt[e[film]] == 0) hash ^= h[e[film]];
++cnt[e[film]];
}
}
if (out_x[x] != -1) {
int film = out_x[x];
if (b[film] < y && y <= d[film]) {
--cnt[e[film]];
if (cnt[e[film]] == 0) hash ^= h[e[film]];
}
}
// cout << '(' << x << ',' << y << ") ";
// REP(i, n) cout << cnt[i] << " \n"[i + 1 == n];
}
while (x > p[idx] + 1) {
--x;
if (in_x[x] != -1) {
int film = in_x[x];
if (b[film] < y && y <= d[film]) {
--cnt[e[film]];
if (cnt[e[film]] == 0) hash ^= h[e[film]];
}
}
if (out_x[x] != -1) {
int film = out_x[x];
if (b[film] < y && y <= d[film]) {
if (cnt[e[film]] == 0) hash ^= h[e[film]];
++cnt[e[film]];
}
}
// cout << '(' << x << ',' << y << ") ";
// REP(i, n) cout << cnt[i] << " \n"[i + 1 == n];
}
ans[idx] = hash;
}
}
REP(i, Q) cout << ans[i] << '\n';
return 0;
}
emthrm