QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#532081 | #2342. Directing Rainfall | Swarthmore# | WA | 1749ms | 269784kb | C++20 | 7.0kb | 2024-08-24 23:59:02 | 2024-08-24 23:59:02 |
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];
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: 3ms
memory: 136456kb
Test #2:
score: 0
Accepted
time: 3ms
memory: 135520kb
Test #3:
score: 0
Accepted
time: 3ms
memory: 136128kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 135568kb
Test #5:
score: 0
Accepted
time: 3ms
memory: 135764kb
Test #6:
score: 0
Accepted
time: 7ms
memory: 135548kb
Test #7:
score: 0
Accepted
time: 7ms
memory: 135664kb
Test #8:
score: 0
Accepted
time: 0ms
memory: 135264kb
Test #9:
score: 0
Accepted
time: 4ms
memory: 134804kb
Test #10:
score: 0
Accepted
time: 4ms
memory: 134892kb
Test #11:
score: 0
Accepted
time: 7ms
memory: 136724kb
Test #12:
score: 0
Accepted
time: 1749ms
memory: 269784kb
Test #13:
score: 0
Accepted
time: 4ms
memory: 136584kb
Test #14:
score: 0
Accepted
time: 12ms
memory: 135152kb
Test #15:
score: 0
Accepted
time: 3ms
memory: 135388kb
Test #16:
score: 0
Accepted
time: 4ms
memory: 135576kb
Test #17:
score: 0
Accepted
time: 7ms
memory: 135772kb
Test #18:
score: 0
Accepted
time: 8ms
memory: 135676kb
Test #19:
score: 0
Accepted
time: 4ms
memory: 135108kb
Test #20:
score: 0
Accepted
time: 8ms
memory: 135140kb
Test #21:
score: 0
Accepted
time: 4ms
memory: 136760kb
Test #22:
score: 0
Accepted
time: 4ms
memory: 135832kb
Test #23:
score: 0
Accepted
time: 10ms
memory: 136252kb
Test #24:
score: -100
Wrong Answer
time: 8ms
memory: 136412kb