QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291307 | #2342. Directing Rainfall | MoRanSky | WA | 3070ms | 185968kb | C++11 | 4.8kb | 2023-12-26 10:52:18 | 2023-12-26 10:52:18 |
Judging History
answer
// Skyqwq
// The additional problem!
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#define ls (p << 1)
#define rs (p << 1 | 1)
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
set<PII> st;
const int N = 5e5 + 5, M = N * 4, INF = 1e9;
int L, R, n, d[M], tot, ans = 2e9, q[N], len, in[N];
vector<int> g[N];
struct E{
int x1, y1, x2, y2, v;
} e[N];
void inline addEdge(int x, int y) {
in[y]++, g[x].push_back(y);
}
struct Node {
int i;
bool operator < (const Node &b) const {
int j = b.i;
int x = max(e[i].x1, e[j].x1);
double k1 = ((double)e[i].y2 - e[i].y1) / (e[i].x2 - e[i].x1), b1 = e[i].y1 - k1 * e[i].x1;
double k2 = ((double)e[j].y2 - e[j].y1) / (e[j].x2 - e[j].x1), b2 = e[j].y1 - k2 * e[j].x1;
return k1 * x + b1 < k2 * x + b2;
}
};
set<Node> s;
typedef set<Node>::iterator SIT;
struct Line {
int x, i, c;
bool operator < (const Line &b) const {
if (x == b.x) return c < b.c;
return x < b.x;
}
} a[N * 2];
int inline get(int x) { return lower_bound(d + 1, d + 1 + tot, x) - d; }
int mx[M << 2], mn[M << 2], add[M << 2], cov[M << 2];
int asc[M << 2], desc[M << 2];
void inline pushup(int p) {
mx[p] = max(mx[ls], mx[rs]), mn[p] = min(mn[ls], mn[rs]);
asc[p] = asc[ls] && asc[rs] && mx[ls] <= mn[rs];
desc[p] = desc[ls] && desc[rs] && mn[ls] >= mx[rs];
}
void inline Add(int p, int k) {
add[p] += k, mx[p] += k, mn[p] += k;
}
void inline cover(int p, int k) {
mx[p] = mn[p] = cov[p] = k, asc[p] = desc[p] = true;
add[p] = 0;
}
void inline pushdown(int p) {
if (cov[p] != -1) {
cover(ls, cov[p]);
cover(rs, cov[p]);
cov[p] = -1;
}
if (add[p]) {
Add(ls, add[p]), Add(rs, add[p]);
add[p] = 0;
}
}
void build(int p, int l, int r) {
cov[p] = -1;
if (l == r) {
mx[p] = mn[p] = (L <= l && l <= R) ? 0 : INF;
asc[p] = desc[p] = true;
return;
}
int mid = (l + r) >> 1;
build(p << 1, l, mid);
build(p << 1 | 1, mid + 1, r);
pushup(p);
}
void change(int p, int l, int r, int x, int y) {
if (x > y) return;
if (x <= l && r <= y) { Add(p, 1); return; }
pushdown(p);
int mid = (l + r) >> 1;
if (x <= mid) change(p << 1, l, mid, x, y);
if (mid < y) change(p << 1 | 1, mid + 1, r, x, y);
pushup(p);
}
int V;
void changeDesc(int p, int l, int r, int x, int y) {
if (x > y) return;
if (x <= l && r <= y) {
if (V <= mn[p]) {
cover(p, V);
return;
} else if (desc[p] && mx[p] <= V) {
V = mn[p];
return;
}
}
pushdown(p);
int mid = (l + r) >> 1;
if (x <= mid) changeDesc(p << 1, l, mid, x, y);
if (mid < y) changeDesc(p << 1 | 1, mid + 1, r, x, y);
pushup(p);
}
void changeAsc(int p, int l, int r, int x, int y) {
if (x > y) return;
if (x <= l && r <= y) {
if (V <= mn[p]) {
cover(p, V);
return;
} else if (asc[p] && mx[p] <= V) {
V = mn[p];
return;
}
}
pushdown(p);
int mid = (l + r) >> 1;
if (mid < y) changeAsc(p << 1 | 1, mid + 1, r, x, y);
if (x <= mid) changeAsc(p << 1, l, mid, x, y);
pushup(p);
}
void work(int p, int l, int r) {
if (l == r) {
if (L <= r && r <= R) ans = min(ans, mn[p]);
return;
}
pushdown(p);
int mid = (l + r) >> 1;
work(p << 1, l, mid);
work(p << 1 | 1, mid + 1, r);
}
void inline toposort() {
int hh = 1, tt = 0;
for (int i = 1; i <= n; i++) if (!in[i]) q[++tt] = i;
while (hh <= tt) {
int u = q[hh++];
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][i];
if (--in[v] == 0) q[++tt] = v;
}
}
}
int main() {
scanf("%d%d%d", &L, &R, &n);
d[1] = L, d[2] = R, tot = 2;
for (int i = 1; i <= n; i++) {
scanf("%d%d%d%d", &e[i].x1, &e[i].y1, &e[i].x2, &e[i].y2);
e[i].v = e[i].x1;
if (e[i].x1 > e[i].x2) swap(e[i].x1, e[i].x2), swap(e[i].y1, e[i].y2);
int x = e[i].x1, y = e[i].x2;
d[++tot] = x, d[++tot] = y;
d[++tot] = x + 1, d[++tot] = y - 1;
a[++len] = (Line) { x, i, 1 };
a[++len] = (Line) { y, i, -1 };
}
sort(a + 1, a + 1 + len);
for (int i = 1; i <= len; i++) {
if (a[i].c == -1) {
s.erase((Node) { a[i].i });
} else {
SIT it = s.lower_bound((Node) { a[i].i });
if (it != s.end()) addEdge(a[i].i, it -> i);
if (it != s.begin()) {
--it;
addEdge(it -> i, a[i].i);
}
s.insert((Node) { a[i].i });
}
}
toposort();
sort(d + 1, d + 1 + tot);
tot = unique(d + 1, d + 1 + tot) - d - 1;
L = get(L), R = get(R);
build(1, 1, tot);
for (int j = 1; j <= n; j++) {
int i = q[j], t = get(e[i].v);
V = INF;
int a = get(e[i].x1 + 1), b = get(e[i].x2 - 1);
change(1, 1, tot, a, b);
if (e[i].v == e[i].x1) changeDesc(1, 1, tot, t, b);
else changeAsc(1, 1, tot, a, t);
}
work(1, 1, tot);
printf("%d\n", ans);
return 0;
}
Details
Test #1:
score: 100
Accepted
time: 0ms
memory: 15836kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 17076kb
Test #3:
score: 0
Accepted
time: 0ms
memory: 16828kb
Test #4:
score: 0
Accepted
time: 5ms
memory: 16964kb
Test #5:
score: 0
Accepted
time: 0ms
memory: 16456kb
Test #6:
score: 0
Accepted
time: 5ms
memory: 17240kb
Test #7:
score: 0
Accepted
time: 2ms
memory: 17372kb
Test #8:
score: 0
Accepted
time: 0ms
memory: 15780kb
Test #9:
score: 0
Accepted
time: 0ms
memory: 17220kb
Test #10:
score: 0
Accepted
time: 0ms
memory: 17056kb
Test #11:
score: 0
Accepted
time: 0ms
memory: 15544kb
Test #12:
score: 0
Accepted
time: 1390ms
memory: 138736kb
Test #13:
score: 0
Accepted
time: 6ms
memory: 17240kb
Test #14:
score: 0
Accepted
time: 5ms
memory: 16516kb
Test #15:
score: 0
Accepted
time: 0ms
memory: 16504kb
Test #16:
score: 0
Accepted
time: 5ms
memory: 16448kb
Test #17:
score: 0
Accepted
time: 0ms
memory: 16276kb
Test #18:
score: 0
Accepted
time: 0ms
memory: 15616kb
Test #19:
score: 0
Accepted
time: 5ms
memory: 16476kb
Test #20:
score: 0
Accepted
time: 5ms
memory: 16604kb
Test #21:
score: 0
Accepted
time: 0ms
memory: 15524kb
Test #22:
score: 0
Accepted
time: 2ms
memory: 17472kb
Test #23:
score: 0
Accepted
time: 0ms
memory: 15988kb
Test #24:
score: 0
Accepted
time: 2ms
memory: 17004kb
Test #25:
score: 0
Accepted
time: 0ms
memory: 17448kb
Test #26:
score: 0
Accepted
time: 0ms
memory: 16880kb
Test #27:
score: 0
Accepted
time: 0ms
memory: 16596kb
Test #28:
score: 0
Accepted
time: 0ms
memory: 15428kb
Test #29:
score: 0
Accepted
time: 0ms
memory: 17108kb
Test #30:
score: 0
Accepted
time: 0ms
memory: 16252kb
Test #31:
score: 0
Accepted
time: 0ms
memory: 16220kb
Test #32:
score: 0
Accepted
time: 0ms
memory: 15648kb
Test #33:
score: 0
Accepted
time: 0ms
memory: 16176kb
Test #34:
score: 0
Accepted
time: 0ms
memory: 16308kb
Test #35:
score: 0
Accepted
time: 1423ms
memory: 136816kb
Test #36:
score: 0
Accepted
time: 1398ms
memory: 176496kb
Test #37:
score: 0
Accepted
time: 1425ms
memory: 185968kb
Test #38:
score: 0
Accepted
time: 1503ms
memory: 185964kb
Test #39:
score: 0
Accepted
time: 1124ms
memory: 112576kb
Test #40:
score: 0
Accepted
time: 1066ms
memory: 162984kb
Test #41:
score: 0
Accepted
time: 3070ms
memory: 172284kb
Test #42:
score: 0
Accepted
time: 2997ms
memory: 172300kb
Test #43:
score: 0
Accepted
time: 2ms
memory: 17232kb
Test #44:
score: 0
Accepted
time: 0ms
memory: 15768kb
Test #45:
score: 0
Accepted
time: 3ms
memory: 17332kb
Test #46:
score: 0
Accepted
time: 0ms
memory: 17000kb
Test #47:
score: 0
Accepted
time: 0ms
memory: 16128kb
Test #48:
score: 0
Accepted
time: 0ms
memory: 15804kb
Test #49:
score: 0
Accepted
time: 0ms
memory: 15424kb
Test #50:
score: 0
Accepted
time: 0ms
memory: 17256kb
Test #51:
score: 0
Accepted
time: 0ms
memory: 16076kb
Test #52:
score: 0
Accepted
time: 0ms
memory: 16700kb
Test #53:
score: 0
Accepted
time: 2ms
memory: 16940kb
Test #54:
score: 0
Accepted
time: 0ms
memory: 17292kb
Test #55:
score: 0
Accepted
time: 4ms
memory: 15436kb
Test #56:
score: 0
Accepted
time: 6ms
memory: 16492kb
Test #57:
score: 0
Accepted
time: 0ms
memory: 17120kb
Test #58:
score: 0
Accepted
time: 2ms
memory: 17292kb
Test #59:
score: 0
Accepted
time: 0ms
memory: 16456kb
Test #60:
score: 0
Accepted
time: 0ms
memory: 17140kb
Test #61:
score: 0
Accepted
time: 5ms
memory: 16084kb
Test #62:
score: 0
Accepted
time: 3ms
memory: 16848kb
Test #63:
score: 0
Accepted
time: 3ms
memory: 16056kb
Test #64:
score: 0
Accepted
time: 3ms
memory: 16932kb
Test #65:
score: 0
Accepted
time: 0ms
memory: 17172kb
Test #66:
score: 0
Accepted
time: 0ms
memory: 16168kb
Test #67:
score: 0
Accepted
time: 3ms
memory: 17356kb
Test #68:
score: 0
Accepted
time: 22ms
memory: 19860kb
Test #69:
score: 0
Accepted
time: 24ms
memory: 19768kb
Test #70:
score: 0
Accepted
time: 23ms
memory: 20520kb
Test #71:
score: 0
Accepted
time: 25ms
memory: 21212kb
Test #72:
score: 0
Accepted
time: 365ms
memory: 53264kb
Test #73:
score: 0
Accepted
time: 373ms
memory: 52072kb
Test #74:
score: 0
Accepted
time: 357ms
memory: 51736kb
Test #75:
score: 0
Accepted
time: 366ms
memory: 51424kb
Test #76:
score: 0
Accepted
time: 337ms
memory: 51952kb
Test #77:
score: 0
Accepted
time: 2705ms
memory: 170448kb
Test #78:
score: 0
Accepted
time: 2691ms
memory: 169408kb
Test #79:
score: 0
Accepted
time: 2502ms
memory: 168276kb
Test #80:
score: 0
Accepted
time: 2462ms
memory: 171628kb
Test #81:
score: 0
Accepted
time: 2624ms
memory: 170288kb
Test #82:
score: 0
Accepted
time: 2544ms
memory: 169256kb
Test #83:
score: 0
Accepted
time: 2315ms
memory: 172168kb
Test #84:
score: 0
Accepted
time: 2435ms
memory: 168968kb
Test #85:
score: 0
Accepted
time: 2613ms
memory: 170748kb
Test #86:
score: 0
Accepted
time: 2520ms
memory: 169840kb
Test #87:
score: 0
Accepted
time: 1376ms
memory: 167320kb
Test #88:
score: 0
Accepted
time: 1458ms
memory: 167728kb
Test #89:
score: -100
Wrong Answer
time: 1623ms
memory: 167012kb