QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291170 | #2342. Directing Rainfall | MoRanSky | WA | 3216ms | 186196kb | C++23 | 4.8kb | 2023-12-26 05:12:11 | 2023-12-26 05:12:11 |
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: 17648kb
Test #2:
score: 0
Accepted
time: 5ms
memory: 16160kb
Test #3:
score: 0
Accepted
time: 0ms
memory: 16824kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 17372kb
Test #5:
score: 0
Accepted
time: 0ms
memory: 15476kb
Test #6:
score: 0
Accepted
time: 2ms
memory: 15548kb
Test #7:
score: 0
Accepted
time: 0ms
memory: 16496kb
Test #8:
score: 0
Accepted
time: 0ms
memory: 15620kb
Test #9:
score: 0
Accepted
time: 2ms
memory: 15844kb
Test #10:
score: 0
Accepted
time: 0ms
memory: 16832kb
Test #11:
score: 0
Accepted
time: 0ms
memory: 15924kb
Test #12:
score: 0
Accepted
time: 1376ms
memory: 137844kb
Test #13:
score: 0
Accepted
time: 2ms
memory: 16308kb
Test #14:
score: 0
Accepted
time: 4ms
memory: 15416kb
Test #15:
score: 0
Accepted
time: 0ms
memory: 16952kb
Test #16:
score: 0
Accepted
time: 0ms
memory: 15884kb
Test #17:
score: 0
Accepted
time: 0ms
memory: 17372kb
Test #18:
score: 0
Accepted
time: 0ms
memory: 15524kb
Test #19:
score: 0
Accepted
time: 4ms
memory: 15760kb
Test #20:
score: 0
Accepted
time: 5ms
memory: 16432kb
Test #21:
score: 0
Accepted
time: 0ms
memory: 15716kb
Test #22:
score: 0
Accepted
time: 4ms
memory: 15804kb
Test #23:
score: 0
Accepted
time: 2ms
memory: 17248kb
Test #24:
score: 0
Accepted
time: 0ms
memory: 16076kb
Test #25:
score: 0
Accepted
time: 2ms
memory: 16728kb
Test #26:
score: 0
Accepted
time: 0ms
memory: 17288kb
Test #27:
score: 0
Accepted
time: 5ms
memory: 16964kb
Test #28:
score: 0
Accepted
time: 0ms
memory: 16168kb
Test #29:
score: 0
Accepted
time: 0ms
memory: 16716kb
Test #30:
score: 0
Accepted
time: 0ms
memory: 17440kb
Test #31:
score: 0
Accepted
time: 0ms
memory: 17436kb
Test #32:
score: 0
Accepted
time: 0ms
memory: 15988kb
Test #33:
score: 0
Accepted
time: 0ms
memory: 17284kb
Test #34:
score: 0
Accepted
time: 5ms
memory: 16536kb
Test #35:
score: 0
Accepted
time: 1398ms
memory: 136744kb
Test #36:
score: 0
Accepted
time: 1414ms
memory: 176808kb
Test #37:
score: 0
Accepted
time: 1426ms
memory: 186196kb
Test #38:
score: 0
Accepted
time: 1466ms
memory: 185912kb
Test #39:
score: 0
Accepted
time: 1121ms
memory: 112332kb
Test #40:
score: 0
Accepted
time: 1069ms
memory: 163048kb
Test #41:
score: 0
Accepted
time: 3216ms
memory: 172288kb
Test #42:
score: 0
Accepted
time: 3071ms
memory: 172288kb
Test #43:
score: 0
Accepted
time: 4ms
memory: 17412kb
Test #44:
score: 0
Accepted
time: 0ms
memory: 17436kb
Test #45:
score: 0
Accepted
time: 5ms
memory: 16140kb
Test #46:
score: 0
Accepted
time: 0ms
memory: 15856kb
Test #47:
score: 0
Accepted
time: 0ms
memory: 16920kb
Test #48:
score: 0
Accepted
time: 0ms
memory: 16324kb
Test #49:
score: 0
Accepted
time: 0ms
memory: 17516kb
Test #50:
score: 0
Accepted
time: 0ms
memory: 16924kb
Test #51:
score: 0
Accepted
time: 0ms
memory: 16248kb
Test #52:
score: 0
Accepted
time: 0ms
memory: 17320kb
Test #53:
score: 0
Accepted
time: 0ms
memory: 16760kb
Test #54:
score: 0
Accepted
time: 5ms
memory: 17284kb
Test #55:
score: 0
Accepted
time: 0ms
memory: 16384kb
Test #56:
score: 0
Accepted
time: 0ms
memory: 16444kb
Test #57:
score: 0
Accepted
time: 0ms
memory: 15664kb
Test #58:
score: 0
Accepted
time: 0ms
memory: 17036kb
Test #59:
score: 0
Accepted
time: 2ms
memory: 17340kb
Test #60:
score: 0
Accepted
time: 2ms
memory: 17492kb
Test #61:
score: 0
Accepted
time: 4ms
memory: 15992kb
Test #62:
score: 0
Accepted
time: 5ms
memory: 17148kb
Test #63:
score: 0
Accepted
time: 0ms
memory: 17736kb
Test #64:
score: 0
Accepted
time: 0ms
memory: 16952kb
Test #65:
score: 0
Accepted
time: 7ms
memory: 16284kb
Test #66:
score: 0
Accepted
time: 4ms
memory: 16936kb
Test #67:
score: 0
Accepted
time: 3ms
memory: 17324kb
Test #68:
score: 0
Accepted
time: 25ms
memory: 20188kb
Test #69:
score: 0
Accepted
time: 25ms
memory: 19820kb
Test #70:
score: 0
Accepted
time: 22ms
memory: 20652kb
Test #71:
score: 0
Accepted
time: 25ms
memory: 20696kb
Test #72:
score: 0
Accepted
time: 354ms
memory: 52568kb
Test #73:
score: 0
Accepted
time: 346ms
memory: 52364kb
Test #74:
score: 0
Accepted
time: 356ms
memory: 52360kb
Test #75:
score: 0
Accepted
time: 367ms
memory: 51508kb
Test #76:
score: 0
Accepted
time: 351ms
memory: 50976kb
Test #77:
score: 0
Accepted
time: 2826ms
memory: 170404kb
Test #78:
score: 0
Accepted
time: 2725ms
memory: 169404kb
Test #79:
score: 0
Accepted
time: 2499ms
memory: 168440kb
Test #80:
score: 0
Accepted
time: 2455ms
memory: 171628kb
Test #81:
score: 0
Accepted
time: 2726ms
memory: 170052kb
Test #82:
score: 0
Accepted
time: 2628ms
memory: 169184kb
Test #83:
score: 0
Accepted
time: 2349ms
memory: 172148kb
Test #84:
score: 0
Accepted
time: 2594ms
memory: 169080kb
Test #85:
score: 0
Accepted
time: 2643ms
memory: 170912kb
Test #86:
score: 0
Accepted
time: 2600ms
memory: 169720kb
Test #87:
score: 0
Accepted
time: 1387ms
memory: 167096kb
Test #88:
score: 0
Accepted
time: 1465ms
memory: 167624kb
Test #89:
score: -100
Wrong Answer
time: 1642ms
memory: 166956kb