QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#85383 | #9020. 测测你的半平面修改查询 | Scintilla | 0 | 1235ms | 57456kb | C++14 | 6.4kb | 2023-03-07 18:02:47 | 2023-03-07 18:02:51 |
Judging History
answer
#pragma GCC optimize("O2")
#include "hpmq.h"
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb emplace_back
#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define drep(i, s, e) for (int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
#define pv(a) cout << #a << " = " << a << endl
#define pa(a, l, r) cout << #a " : "; rep(_, l, r) cout << a[_] << ' '; cout << endl
using ull = unsigned long long;
using pii = pair <int, int>;
const int INF = 0x3f3f3f3f;
const int P = 1e9 + 7;
const int N = 6e5 + 10;
const int M = 3e4 + 10;
int read() {
int x = 0, f = 1; char c = getchar();
for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1;
for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
return x * f;
}
int inc(int a, int b) { return (a += b) >= P ? a - P : a; }
int dec(int a, int b) { return (a -= b) < 0 ? a + P : a; }
int mul(int a, int b) { return 1ll * a * b % P; }
int qpow(int a, int b) { int res = 1; for (; b; b >>= 1, a = mul(a, a)) if (b & 1) res = mul(res, a); return res; }
mt19937_64 rng(time(0));
int Rand(int l, int r) {
return l + rng() % (r - l + 1);
}
struct frac {
int p, q;
frac(int _p = 0, int _q = 1) {
p = _p, q = _q;
if (q < 0) p = -p, q = -q;
}
friend bool operator < (frac a, frac b) {
return 1ll * a.p * b.q < 1ll * b.p * a.q;
}
friend bool operator == (frac a, frac b) {
return 1ll * a.p * b.q == 1ll * b.p * a.q;
}
void print() {
printf("%d/%d\n", p, q);
}
} ;
struct vec {
int x, y;
void init() {
x = read(), y = read();
}
friend bool operator < (vec a, vec b) {
return a.x == b.x ? a.y < b.y : a.x < b.x;
}
void print() {
printf("(%d, %d)\n", x, y);
}
} ;
struct line {
int a, b, c;
frac k;
line(int _a = 0, int _b = 1, int _c = 0) {
a = _a, b = _b, c = _c;
k = frac(-a, b);
}
bool chk(vec p) {
return a * p.x + b * p.y + c < 0;
}
bool above(vec p) {
if (b > 0) return a * p.x + b * p.y + c < 0;
else return a * p.x + b * p.y + c > 0;
}
friend bool operator < (line l1, line l2) {
if (l1.k == l2.k) return frac(-l1.c, l1.b) < frac(-l2.c, l2.b);
else return l2.k < l1.k;
}
} ;
frac inter(line l1, line l2) {
return frac(l2.c * l1.b - l1.c * l2.b, l1.a * l2.b - l2.a * l1.b);
}
#define ls lson[u]
#define rs rson[u]
int tot, lson[N], rson[N];
vec p[N];
Data dat[N];
Operation laz[N];
void down(int u, Operation o) {
o.apply(dat[u]);
o.apply(laz[u]);
}
void pushdown(int u) {
down(ls, laz[u]);
down(rs, laz[u]);
laz[u].clr();
}
void maintain(int u) {
p[u] = p[ls];
dat[u].add(dat[ls], dat[rs]);
}
int newnode() {
return ++ tot;
}
void undo() {
pushdown(tot);
lson[tot] = rson[tot] = 0;
p[tot] = vec();
dat[tot].clr();
-- tot;
}
struct O {
line l;
Operation o;
} op[N];
int n, m, B, rk[N];
ull pre[N], suf[N], h[N], key[N];
void solve(int l, int r, vector <int> c) {
int len = r - l + 1, cur = tot;
auto work = [&]() {
for (auto it : c) h[it] = 0;
vector <int> ord;
rep(i, l, r) ord.pb(i);
sort(ord.begin(), ord.end(), [&](int i, int j) {
return op[i].l < op[j].l;
});
rep(i, 0, len - 1) {
key[ord[i]] = rng() % (1ll << 60);
pre[ord[i]] = i ? pre[ord[i - 1]] : 0;
if (op[ord[i]].l.b < 0) pre[ord[i]] ^= key[ord[i]];
rk[ord[i]] = i;
}
drep(i, len - 1, 0) {
suf[ord[i]] = i < len - 1 ? suf[ord[i + 1]] : 0;
if (op[ord[i]].l.b > 0) suf[ord[i]] ^= key[ord[i]];
}
sort(c.begin(), c.end(), [&](int i, int j) {
return p[i] < p[j];
});
vector <pair <frac, pii> > px;
rep(i, 0, len - 1) rep(j, i + 1, len - 1) if (op[ord[j]].l.k < op[ord[i]].l.k) {
px.pb(mp(inter(op[ord[i]].l, op[ord[j]].l), mp(ord[i], ord[j])));
}
px.pb(mp(frac(INF, 1), mp(0, 0)));
sort(px.begin(), px.end(), [&](pair <frac, pii> a, pair <frac, pii> b) {
if (a.first == b.first) {
if (rk[a.second.first] == rk[b.second.first]) {
return rk[a.second.second] < rk[b.second.second];
}
else return rk[a.second.first] < rk[b.second.first];
}
else return a.first < b.first;
});
for (int i = 0, j = 0; i < px.size(); ++ i) {
for (; j < c.size() && p[c[j]].x < px[i].first; ++ j) {
auto it = partition_point(ord.begin(), ord.end(), [&](int k) {
return !op[k].l.above(p[c[j]]);
});
if (it != ord.end()) h[c[j]] ^= suf[*it];
if (it != ord.begin()) h[c[j]] ^= pre[*(-- it)];
}
int u = px[i].second.first, v = px[i].second.second;
if (!u && !v) continue;
assert(rk[u] + 1 == rk[v]);
swap(ord[rk[u]], ord[rk[v]]);
swap(rk[u], rk[v]);
if (op[u].l.b < 0) pre[v] ^= key[u];
else suf[v] ^= key[u];
if (op[v].l.b < 0) pre[u] ^= key[v];
else suf[u] ^= key[v];
}
sort(c.begin(), c.end(), [&](int i, int j) {
return h[i] < h[j];
});
vector <int> nc;
for (int i = 0, j; i < c.size(); i = j + 1) {
for (j = i; j + 1 < c.size() && h[c[j + 1]] == h[c[i]]; ++ j) ;
if (i < j) {
rep(k, i + 1, j) {
int u = newnode();
ls = k == i + 1 ? c[i] : u - 1, rs = c[k];
maintain(u);
}
nc.pb(tot);
}
else nc.pb(c[i]);
}
c = nc;
} ;
work();
if (l == r) {
bool flag = false;
for (auto it : c) {
if (op[l].l.chk(p[it])) {
dat[it].print();
down(it, op[l].o);
flag = true;
break;
}
}
if (!flag) Data().print();
while (tot > cur) undo();
return;
}
int mid = (l + r) >> 1;
solve(l, mid, c);
solve(mid + 1, r, c);
while (tot > cur) undo();
}
#undef ls
#undef rs
void solve(const int _n, const int _m, const int *_x, const int *_y, const Data *_d,
const int *_a, const int *_b, const int *_c, const Operation *_o) {
n = _n, m = _m, tot = n, B = sqrt(n);
rep(i, 1, n) p[i].x = _x[i - 1], p[i].y = _y[i - 1], dat[i] = _d[i - 1];
rep(i, 1, m) op[i].l = line(_a[i - 1], _b[i - 1], _c[i - 1]), op[i].o = _o[i - 1];
for (int l = 1, r; l <= m; l = r + 1) {
r = min(l + B - 1, m);
vector <int> all;
rep(i, 1, n) all.pb(i);
solve(l, r, all);
}
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 100ms
memory: 30476kb
input:
20000 5245 -9733 6 2898 -2273 6 -3025 13598 7 -2111 542 3 -913 -1516 6 -1525 -1050 2 17646 4583 6 -2101 -1295 10 -635 1367 4 -2828 1004 6 -1497 -2603 5 -3415 -3290 7 3995 -6478 2 -2093 -203 6 2748 181 9 -9456 206 6 -15645 14633 9 -4783 555 3 -4383 425 5 -20919 36410 1 1921 -405 1 3934 8809 4 -1303 -...
output:
975335 4132363247
result:
wrong answer The answer is wrong.
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 113ms
memory: 57456kb
input:
200000 -1014 -2657 4 -441 -2850 9 -860 3331 8 6027 -6526 6 144250 69365 6 -2855 -3780 9 1460 2333 6 -644 1051 10 -4535 -3692 1 3573 -175 4 232 2495 5 -3996 2251 7 6945 -17184 8 -9520 1403 1 2112 1387 8 -1205 1496 8 2673 605 10 -2820 -973 3 558 -846 2 -17020 -11100 7 868 2321 8 -580 -758 6 1785 -1253...
output:
636177 1187083383
result:
wrong answer The answer is wrong.
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #45:
score: 0
Wrong Answer
time: 1235ms
memory: 38376kb
input:
65536 -128 -128 6 -128 -127 3 -128 -126 3 -128 -125 2 -128 -124 8 -128 -123 8 -128 -122 6 -128 -121 3 -128 -120 10 -128 -119 2 -128 -118 6 -128 -117 9 -128 -116 7 -128 -115 1 -128 -114 8 -128 -113 3 -128 -112 4 -128 -111 6 -128 -110 9 -128 -109 10 -128 -108 6 -128 -107 7 -128 -106 9 -128 -105 3 -128...
output:
14101300 149148157
result:
wrong answer The answer is wrong.
Subtask #6:
score: 0
Wrong Answer
Test #49:
score: 0
Wrong Answer
time: 443ms
memory: 57204kb
input:
200000 0 0 9 0 2 7 0 4 1 0 6 4 0 8 2 0 10 2 0 12 5 0 14 10 0 16 7 0 18 4 0 20 4 0 22 9 0 24 8 0 26 4 0 28 8 0 30 5 0 32 4 0 34 9 0 36 3 0 38 7 0 40 4 0 42 10 0 44 4 0 46 6 0 48 3 0 50 7 0 52 9 0 54 7 0 56 8 0 58 8 0 60 4 0 62 10 0 64 2 0 66 4 0 68 4 0 70 1 0 72 1 0 74 6 0 76 1 0 78 4 0 80 3 0 82 7 0...
output:
18209812 664083198
result:
wrong answer The answer is wrong.
Subtask #7:
score: 0
Time Limit Exceeded
Test #51:
score: 0
Time Limit Exceeded
input:
200000 -1099 1879 7 1402 -488 8 -9770 8838 3 -177 -1714 9 2929 1099 9 4906 385 1 1606 5775 10 -2824 3929 10 997 2113 8 2897 -1592 4 -1679 8134 10 1988 405 4 -124 -112 5 -7851 12185 10 -2048 -1963 10 140 -2168 4 16857 -9907 4 -2719 10 8 1383 -648 9 2161 -464 9 1917 -1321 3 607 -2034 10 -22 1839 6 -30...
output:
result:
Subtask #8:
score: 0
Skipped
Dependency #1:
0%