QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#209476 | #29. Posters on the wall | jrjyy | 0 | 320ms | 944528kb | C++20 | 5.8kb | 2023-10-10 15:19:40 | 2023-10-10 15:19:40 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
constexpr int Pool = 2e7;
struct Tag {
int add = 0, madd = 0, delta = 0;
void apply(const Tag &y) {
if (madd == add + y.madd) {
delta += y.delta;
} else if (add + y.madd < madd) {
madd = add + y.madd;
delta = y.delta;
}
add += y.add;
}
};
struct Info {
int mn = 0, len = 0;
i64 ans = 0;
void apply(const Tag &y) {
if (mn + y.madd == 0) {
ans += 1ll * len * y.delta;
}
mn += y.add;
}
};
Info operator+(const Info &a, const Info &b) {
Info c{};
c.mn = std::min(a.mn, b.mn);
c.len = a.len * (a.mn == c.mn) + b.len * (b.mn == c.mn);
c.ans = a.ans + b.ans;
return c;
}
std::function<int(int, int)> get;
struct Node {
Node *l, *r;
Info s;
Tag t;
} *null;
Node pool[Pool], *ptr = pool;
Node *newNode(const Node &x) {
*++ptr = x;
return ptr;
}
void clone(Node *&u, int l, int r) {
if (u == null) {
u = newNode(Node{null, null, Info{}, Tag{}});
u->s.len = get(l, r);
} else {
u = newNode(*u);
}
}
void pull(Node *u) {
u->s = u->l->s + u->r->s;
}
void apply(Node *u, const Tag &x) {
u->s.apply(x);
u->t.apply(x);
}
void push(Node *u, int l, int m, int r) {
clone(u->l, l, m);
apply(u->l, u->t);
clone(u->r, m, r);
apply(u->r, u->t);
u->t = Tag{};
}
void rangeApply(Node *u, int l, int r, int ql, int qr, const Tag &x) {
if (r <= ql || qr <= l) {
return;
}
if (ql <= l && r <= qr) {
apply(u, x);
return;
}
int m = (l + r) / 2;
push(u, l, m, r);
rangeApply(u->l, l, m, ql, qr, x);
rangeApply(u->r, m, r, ql, qr, x);
pull(u);
}
i64 rangeQuery(Node *u, int l, int r, int ql, int qr) {
if (r <= ql || qr <= l) {
return 0;
}
if (ql <= l && r <= qr) {
return u->s.ans;
}
int m = (l + r) / 2;
push(u, l, m, r);
return rangeQuery(u->l, l, m, ql, qr) + rangeQuery(u->r, m, r, ql, qr);
}
i64 rangeQuery(Node *u, int m, int ql, int qr) {
Node *optr = ptr;
Node x = *u;
i64 res = rangeQuery(u, 0, m, ql, qr);
*u = x;
ptr = optr;
return res;
}
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
null = new Node{};
null->l = null->r = null;
int _r, _c, n, q;
std::cin >> _r >> _c >> n >> q;
std::vector<std::tuple<int, int, int, int>> s;
std::vector<int> vx{0, _r}, vy{0, _c};
for (int i = 0; i < n; ++i) {
int x1, y1, x2, y2;
std::cin >> x1 >> y1 >> x2 >> y2;
std::tie(x1, x2) = std::minmax({x1, x2});
std::tie(y1, y2) = std::minmax({y1, y2});
s.emplace_back(x1, y1, x2, y2);
vx.push_back(x1);
vy.push_back(y1);
vx.push_back(x2);
vy.push_back(y2);
}
std::sort(vx.begin(), vx.end());
vx.erase(std::unique(vx.begin(), vx.end()), vx.end());
std::sort(vy.begin(), vy.end());
vy.erase(std::unique(vy.begin(), vy.end()), vy.end());
std::vector<std::vector<std::tuple<int, int, int>>> mdf(vx.size());
for (int i = 0; i < n; ++i) {
int x1, y1, x2, y2;
std::tie(x1, y1, x2, y2) = s[i];
x1 = std::lower_bound(vx.begin(), vx.end(), x1) - vx.begin();
y1 = std::lower_bound(vy.begin(), vy.end(), y1) - vy.begin();
x2 = std::lower_bound(vx.begin(), vx.end(), x2) - vx.begin();
y2 = std::lower_bound(vy.begin(), vy.end(), y2) - vy.begin();
mdf[x1].emplace_back(y1, y2, 1);
mdf[x2].emplace_back(y1, y2, -1);
}
get = [&](int l, int r) {
return vy[r] - vy[l];
};
const int m = int(vy.size()) - 1;
std::vector<Node *> root(vx.size() + 1, null);
clone(root[0], 0, m);
for (int i = 0; i < int(vx.size()); ++i) {
root[i + 1] = root[i];
clone(root[i + 1], 0, m);
for (auto p : mdf[i]) {
int y1, y2, delta;
std::tie(y1, y2, delta) = p;
rangeApply(root[i + 1], 0, m, y1, y2, Tag{delta, std::min(delta, 0), 0});
}
if (i < int(vx.size()) - 1) {
rangeApply(root[i + 1], 0, m, 0, m, Tag{0, 0, vx[i + 1] - vx[i]});
}
}
auto query = [&](int x, int y) -> i64 {
int px = std::upper_bound(vx.begin(), vx.end(), x) - vx.begin() - 1;
int py = std::upper_bound(vy.begin(), vy.end(), y) - vy.begin() - 1;
i64 ans = rangeQuery(root[px], m, 0, py), tmp = ans;
i64 tx = 0, ty = 0, txy = 0;
if (vx[px] != x) {
tx = rangeQuery(root[px + 1], m, 0, py) - tmp;
ans += tx / (vx[px + 1] - vx[px]) * (x - vx[px]);
}
if (vy[py] != y) {
ty = rangeQuery(root[px], m, 0, py + 1) - tmp;
ans += ty / (vy[py + 1] - vy[py]) * (y - vy[py]);
}
if (vx[px] != x && vy[py] != y) {
txy = rangeQuery(root[px + 1], m, 0, py + 1) - tx - ty - tmp;
ans += txy / (vx[px + 1] - vx[px]) * (x - vx[px]) / (vy[py + 1] - vy[py]) * (y - vy[py]);
}
return ans;
};
i64 ans = 0;
auto get = [&](int &x, int v, int k) {
x = (x + ans % k * v) % k;
};
while (q--) {
int x1, y1, x2, y2, _v;
std::cin >> x1 >> y1 >> x2 >> y2 >> _v;
get(x1, _v, _r + 1);
get(y1, _v, _c + 1);
get(x2, _v, _r + 1);
get(y2, _v, _c + 1);
std::tie(x1, x2) = std::minmax({x1, x2});
std::tie(y1, y2) = std::minmax({y1, y2});
ans = 1ll * (x2 - x1) * (y2 - y1);
ans -= query(x2, y2) - query(x1, y2) - query(x2, y1) + query(x1, y1);
std::cout << ans << "\n";
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 48ms
memory: 941040kb
input:
500 500 398 500 550 174 98 170 101 413 442 406 435 394 123 486 121 360 139 361 136 7 216 8 208 282 302 284 308 134 134 140 131 160 27 161 26 437 364 442 356 162 438 173 445 180 151 178 146 1 298 24 310 255 328 254 335 119 42 128 39 22 120 17 125 81 140 85 139 98 50 100 40 101 250 98 291 53 369 37 37...
output:
1300 2530 1196 876 8644 10287 352 15496 0 16392 5265 22950 41 8714 39410 142 1668 3306 5006 10045 17502 14893 4373 12187 584 1976 30643 5684 1411 5775 6609 94749 2922 44675 11812 879 4612 19739 3225 1344 1938 3738 60764 26114 78492 1062 105691 0 12195 6144 9847 7155 3674 30616 20652 15345 30671 9826...
result:
wrong answer 1st lines differ - expected: '588', found: '1300'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #2:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Wrong Answer
Test #25:
score: 0
Wrong Answer
time: 320ms
memory: 944528kb
input:
100002 100002 50000 50000 100003 26929 99995 26935 100002 22715 99995 22721 100002 0 14154 6 14160 0 14203 6 14209 0 57260 6 57266 8057 0 8063 7 39109 99995 39115 100002 0 38521 6 38527 0 82355 6 82361 37037 99995 37043 100002 83083 99995 83089 100002 0 4746 6 4752 84357 99995 84363 100002 1659 0 16...
output:
2892527082 132070 283121 92610 252256 18942 82002 0 0 206845 423216 0 298464 285432 251655 307710 175115 30312 0 12666 53880 54720 118210 187195 48252 184518 202788 18558 14037 0 0 341891 14661 80280 63133 295056 0 90575 105243 193212 0 169805 0 164382 209468 192500 26021 0 226328 155105 397765 1529...
result:
wrong answer 1st lines differ - expected: '1349982', found: '2892527082'
Subtask #7:
score: 0
Skipped
Dependency #6:
0%