QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#532215 | #2342. Directing Rainfall | Swarthmore# | WA | 2960ms | 270680kb | C++20 | 7.0kb | 2024-08-25 01:32:36 | 2024-08-25 01:32:36 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define sz(x) (int)(x).size()
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
const char nl = '\n';
const ll id= 0;
const ll SZ = 131072*16;
ll sum[2*SZ], lazy[2*SZ][4];
void push(int ind, ll L, ll R) {
/*sum[index] = combineUpd(sum[index], lazy[index]);
if (L != R) lazy[2*index] = combineUpd(lazy[2*index], lazy[index]), lazy[2*index+1] = combineUpd(lazy[2*index+1], lazy[index]);
lazy[index] = id;*/
int indL = 2*ind, indR = 2*ind+1;
sum[ind] += lazy[ind][0];
if (L != R) {
lazy[indL][0] += lazy[ind][0];
lazy[indL][1] += lazy[ind][0];
lazy[indR][0] += lazy[ind][0];
lazy[indR][1] += lazy[ind][0];
}
sum[ind] = min(sum[ind], lazy[ind][1]);
if (L != R) {
lazy[indL][1] = min(lazy[indL][1], lazy[ind][1]);
lazy[indR][1] = min(lazy[indR][1], lazy[ind][1]);
}
if (lazy[ind][2]) {
if (L != R) {
lazy[indL][2] = 1;
lazy[indR][2] = 1;
ll val = min(sum[indL]+lazy[indL][0], lazy[indL][1]);
lazy[indR][1] = min(lazy[indR][1], val);
}
}
if (lazy[ind][3]) {
if (L != R) {
lazy[indL][3] = 1;
lazy[indR][3] = 1;
ll val = min(sum[indR]+lazy[indR][0], lazy[indR][1]);
lazy[indL][1] = min(lazy[indL][1], val);
}
}
lazy[ind][0] = 0;
lazy[ind][1] = 1e18;
lazy[ind][2] = 0;
lazy[ind][3] = 0;
}
void pull(int index) {
sum[index] = min(sum[2*index], sum[2*index+1]);
}
ll query(int lo, int hi, int index = 1, ll L = 0, ll R = SZ-1) {
push(index, L, R);
if (lo > R || L > hi) return 1e18;
if (lo <= L && R <= hi) return sum[index];
int M = (L+R) / 2;
return min(query(lo, hi, 2*index, L, M), query(lo, hi, 2*index+1, M+1, R));
}
ll update(int lo, int hi, ll increase, int ty, ll cur = 1e18, int index = 1,
ll L = 0, ll R = SZ-1) {
push(index, L, R);
if (hi < L || R < lo) return 1e18;
if (lo <= L && R <= hi) {
lazy[index][ty] = increase;
lazy[index][1] = min(lazy[index][1], cur);
push(index, L, R);
/*if (ty == 3) {
cout << L << " " << R << " UPD " << sum[index] << " " << cur << endl;
}*/
return min(sum[index], cur);
}
int M = (L+R) / 2;
/*if (ty == 3) {
cout << L << " " << R << " " << cur << endl;
}*/
if (ty == 0) {
update(lo, hi, increase, ty, cur, 2*index, L, M); update(lo, hi, increase, ty, cur, 2*index+1, M+1, R);
} else if (ty == 2) {
cur = min(cur, update(lo, hi, increase, ty, cur, 2*index, L, M));
cur = min(cur, update(lo, hi, increase, ty, cur, 2*index+1, M+1, R));
} else if (ty == 3) {
cur = min(cur, update(lo, hi, increase, ty, cur, 2*index+1, M+1, R));
cur = min(cur, update(lo, hi, increase, ty, cur, 2*index, L, M));
}
/*if (ty == 3) {
cout << "DONE " << L << " " << R << " " << cur << endl;
}*/
pull(index);
return cur;
}
ll X;
struct Line {
ll x1, x2, y1, y2, v;
Line (ll _x1, ll _x2, ll _y1, ll _y2, ll _v) {
x1 = _x1;
x2 = _x2;
y1 = _y1;
y2 = _y2;
v = _v;
if (x1 > x2) {
swap(x1, x2);
swap(y1, y2);
}
}
bool operator<(const Line &l2) const{
__int128 v1 = (X - x1) * (y2 - y1) + y1 * (x2 - x1);
__int128 v2 = (X - l2.x1) * (l2.y2 - l2.y1) + l2.y1 * (l2.x2 - l2.x1);
v1 *= l2.x2 - l2.x1;
v2 *= x2 - x1;
return v1 < v2;
}
};
void solve() {
F0R(i, 2*SZ) lazy[i][1] = 1e18;
ll totL, totR; cin >> totL >> totR;
int N; cin >> N;
if (N == 0) {
cout << 0 << nl; return;
}
vector<vi> graph(N);
ll X1[N], Y1[N], X2[N], Y2[N];
F0R(i, N) cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
vector<array<ll, 3>> ev;
F0R(i, N) {
ev.pb({min(X1[i], X2[i]), 0, i});
ev.pb({max(X1[i], X2[i]), 1, i});
}
sort(all(ev));
set<Line> lines;
if (totL < ev[0][0]) {
cout << 0 << nl; return;
}
if (totR > ev.back()[0]) {
cout << 0 << nl; return;
}
F0R(i, sz(ev)) {
auto a = ev[i];
X = a[0];
if (a[1] == 0) {
ll ind = a[2];
Line cur(X1[a[2]], X2[a[2]], Y1[a[2]], Y2[a[2]], ind);
lines.ins(cur);
auto it = lines.find(cur);
if (it != lines.begin()) {
it--;
graph[a[2]].pb(it->v);
it++;
}
it++;
if (it != lines.end()) {
graph[it->v].pb(a[2]);
}
} else {
Line cur(X1[a[2]], X2[a[2]], Y1[a[2]], Y2[a[2]], a[2]);
lines.erase(cur);
}
if (sz(lines) == 0 && i < sz(ev) - 1 && max(totL, a[0]) < min(totR, ev[i+1][0])) {
cout << 0 << nl; return;
}
/*trav(a, lines) {
cout << a.v << " ";
}
cout << nl;*/
}
vi ord;
int ind[N]; F0R(i, N) ind[i] = 0;
F0R(i, N) {
trav(a, graph[i]) ind[a]++;
}
queue<int> q; F0R(i, N) if (ind[i] == 0) q.push(i);
while (!q.empty()) {
int v = q.front(); q.pop();
ord.pb(v);
trav(a, graph[v]) {
ind[a]--;
if (ind[a] == 0) {
q.push(a);
}
}
}
vi coords;
coords.pb(totL); coords.pb(totR);
F0R(i, N) {
coords.pb(X1[i]); coords.pb(X2[i]);
}
sort(all(coords)); coords.resize(unique(all(coords)) - coords.begin());
totL = lb(all(coords), totL) - coords.begin();
totR = lb(all(coords), totR) - coords.begin();
F0R(i, N) {
X1[i] = lb(all(coords), X1[i]) - coords.begin();
X2[i] = lb(all(coords), X2[i]) - coords.begin();
}
update(0, totL-1, 1e18, 0);
update(totR+1, SZ-1, 1e18, 0);
trav(a, ord) {
//cout << X1[a] << " " << X2[a] << nl;
if (X1[a] < X2[a]) {
update(X1[a], X2[a], 1, 3);
update(X1[a]+1, X2[a], 1, 0);
} else {
update(X2[a], X1[a], 1, 2);
/*F0R(i, 12) {
cout << min(10ll, query(i, i)) << " ";
}
cout << nl;*/
update(X2[a], X1[a]-1, 1, 0);
}
/*F0R(i, 12) {
cout << min(10ll, query(i, i)) << " ";
}
cout << nl;*/
}
cout << query(totL, totR) << nl;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 8ms
memory: 134816kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 135960kb
Test #3:
score: 0
Accepted
time: 4ms
memory: 135236kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 135104kb
Test #5:
score: 0
Accepted
time: 3ms
memory: 134976kb
Test #6:
score: 0
Accepted
time: 4ms
memory: 135176kb
Test #7:
score: 0
Accepted
time: 9ms
memory: 135284kb
Test #8:
score: 0
Accepted
time: 16ms
memory: 136424kb
Test #9:
score: 0
Accepted
time: 8ms
memory: 136248kb
Test #10:
score: 0
Accepted
time: 4ms
memory: 135476kb
Test #11:
score: 0
Accepted
time: 8ms
memory: 136588kb
Test #12:
score: 0
Accepted
time: 1795ms
memory: 270284kb
Test #13:
score: 0
Accepted
time: 8ms
memory: 135636kb
Test #14:
score: 0
Accepted
time: 8ms
memory: 135372kb
Test #15:
score: 0
Accepted
time: 4ms
memory: 136552kb
Test #16:
score: 0
Accepted
time: 7ms
memory: 135028kb
Test #17:
score: 0
Accepted
time: 0ms
memory: 135104kb
Test #18:
score: 0
Accepted
time: 4ms
memory: 135260kb
Test #19:
score: 0
Accepted
time: 4ms
memory: 136312kb
Test #20:
score: 0
Accepted
time: 8ms
memory: 136156kb
Test #21:
score: 0
Accepted
time: 8ms
memory: 134968kb
Test #22:
score: 0
Accepted
time: 8ms
memory: 135008kb
Test #23:
score: 0
Accepted
time: 12ms
memory: 136052kb
Test #24:
score: 0
Accepted
time: 9ms
memory: 136680kb
Test #25:
score: 0
Accepted
time: 11ms
memory: 136484kb
Test #26:
score: 0
Accepted
time: 16ms
memory: 135344kb
Test #27:
score: 0
Accepted
time: 8ms
memory: 135252kb
Test #28:
score: 0
Accepted
time: 0ms
memory: 135204kb
Test #29:
score: 0
Accepted
time: 3ms
memory: 136280kb
Test #30:
score: 0
Accepted
time: 3ms
memory: 136304kb
Test #31:
score: 0
Accepted
time: 12ms
memory: 135552kb
Test #32:
score: 0
Accepted
time: 4ms
memory: 135020kb
Test #33:
score: 0
Accepted
time: 15ms
memory: 135420kb
Test #34:
score: 0
Accepted
time: 12ms
memory: 136592kb
Test #35:
score: 0
Accepted
time: 1783ms
memory: 270120kb
Test #36:
score: 0
Accepted
time: 395ms
memory: 214324kb
Test #37:
score: 0
Accepted
time: 1768ms
memory: 269452kb
Test #38:
score: 0
Accepted
time: 1815ms
memory: 270680kb
Test #39:
score: 0
Accepted
time: 1264ms
memory: 222028kb
Test #40:
score: 0
Accepted
time: 972ms
memory: 224336kb
Test #41:
score: 0
Accepted
time: 2924ms
memory: 246644kb
Test #42:
score: 0
Accepted
time: 2960ms
memory: 245496kb
Test #43:
score: 0
Accepted
time: 0ms
memory: 134676kb
Test #44:
score: 0
Accepted
time: 3ms
memory: 135596kb
Test #45:
score: 0
Accepted
time: 4ms
memory: 134876kb
Test #46:
score: 0
Accepted
time: 16ms
memory: 134788kb
Test #47:
score: 0
Accepted
time: 0ms
memory: 135264kb
Test #48:
score: 0
Accepted
time: 4ms
memory: 135596kb
Test #49:
score: 0
Accepted
time: 4ms
memory: 136604kb
Test #50:
score: 0
Accepted
time: 7ms
memory: 135008kb
Test #51:
score: 0
Accepted
time: 8ms
memory: 136536kb
Test #52:
score: 0
Accepted
time: 3ms
memory: 135960kb
Test #53:
score: 0
Accepted
time: 4ms
memory: 135208kb
Test #54:
score: 0
Accepted
time: 14ms
memory: 135184kb
Test #55:
score: 0
Accepted
time: 3ms
memory: 136408kb
Test #56:
score: 0
Accepted
time: 8ms
memory: 136308kb
Test #57:
score: 0
Accepted
time: 8ms
memory: 134796kb
Test #58:
score: 0
Accepted
time: 0ms
memory: 135416kb
Test #59:
score: 0
Accepted
time: 4ms
memory: 136592kb
Test #60:
score: 0
Accepted
time: 8ms
memory: 135124kb
Test #61:
score: 0
Accepted
time: 4ms
memory: 136420kb
Test #62:
score: 0
Accepted
time: 11ms
memory: 135292kb
Test #63:
score: 0
Accepted
time: 12ms
memory: 136700kb
Test #64:
score: 0
Accepted
time: 13ms
memory: 136392kb
Test #65:
score: 0
Accepted
time: 15ms
memory: 136732kb
Test #66:
score: 0
Accepted
time: 11ms
memory: 135480kb
Test #67:
score: 0
Accepted
time: 3ms
memory: 136356kb
Test #68:
score: 0
Accepted
time: 32ms
memory: 136952kb
Test #69:
score: -100
Wrong Answer
time: 28ms
memory: 138240kb