QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#531930 | #2342. Directing Rainfall | Swarthmore# | WA | 1647ms | 169992kb | C++20 | 5.2kb | 2024-08-24 23:11:47 | 2024-08-24 23:11:48 |
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];
ll combine(ll A, ll B) {
return min(A, B);
}
ll combineUpd(ll A, ll B) {
return A+B;
}
void push(int index, 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;
}
void pull(int index) {
sum[index] = combine(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 combine(query(lo, hi, 2*index, L, M), query(lo, hi, 2*index+1, M+1, R));
}
void update(int lo, int hi, ll increase, int index = 1, ll L = 0, ll R = SZ-1) {
push(index, L, R);
if (hi < L || R < lo) return;
if (lo <= L && R <= hi) {
lazy[index] = increase;
push(index, L, R);
return;
}
int M = (L+R) / 2;
update(lo, hi, increase, 2*index, L, M); update(lo, hi, increase, 2*index+1, M+1, R);
pull(index);
}
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() {
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();
}
trav(a, ord) {
if (X1[a] < X2[a]) {
int v = query(X1[a], X1[a]);
int v2 = query(X1[a]+1, X2[a]);
if (v > v2) {
update(X1[a], X1[a], v2-v);
}
update(X1[a]+1, X2[a], 1);
} else {
int v = query(X1[a], X1[a]);
int v2 = query(X2[a], X1[a]-1);
if (v > v2) {
update(X1[a], X2[a], v2-v);
}
update(X2[a], X1[a]-1, 1);
}
}
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: 0ms
memory: 22028kb
Test #2:
score: 0
Accepted
time: 3ms
memory: 22136kb
Test #3:
score: 0
Accepted
time: 0ms
memory: 3876kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 3620kb
Test #5:
score: 0
Accepted
time: 0ms
memory: 3552kb
Test #6:
score: 0
Accepted
time: 0ms
memory: 3636kb
Test #7:
score: 0
Accepted
time: 0ms
memory: 3828kb
Test #8:
score: 0
Accepted
time: 0ms
memory: 22096kb
Test #9:
score: 0
Accepted
time: 0ms
memory: 3620kb
Test #10:
score: 0
Accepted
time: 0ms
memory: 3572kb
Test #11:
score: 0
Accepted
time: 0ms
memory: 3512kb
Test #12:
score: 0
Accepted
time: 1647ms
memory: 169992kb
Test #13:
score: 0
Accepted
time: 0ms
memory: 3824kb
Test #14:
score: 0
Accepted
time: 0ms
memory: 22332kb
Test #15:
score: 0
Accepted
time: 0ms
memory: 3888kb
Test #16:
score: 0
Accepted
time: 0ms
memory: 3536kb
Test #17:
score: 0
Accepted
time: 0ms
memory: 22024kb
Test #18:
score: 0
Accepted
time: 0ms
memory: 21920kb
Test #19:
score: 0
Accepted
time: 4ms
memory: 22028kb
Test #20:
score: 0
Accepted
time: 0ms
memory: 22064kb
Test #21:
score: 0
Accepted
time: 0ms
memory: 22100kb
Test #22:
score: 0
Accepted
time: 0ms
memory: 22288kb
Test #23:
score: 0
Accepted
time: 0ms
memory: 22064kb
Test #24:
score: 0
Accepted
time: 0ms
memory: 22032kb
Test #25:
score: 0
Accepted
time: 0ms
memory: 22092kb
Test #26:
score: 0
Accepted
time: 0ms
memory: 22256kb
Test #27:
score: 0
Accepted
time: 0ms
memory: 21996kb
Test #28:
score: 0
Accepted
time: 0ms
memory: 21980kb
Test #29:
score: 0
Accepted
time: 0ms
memory: 3568kb
Test #30:
score: -100
Wrong Answer
time: 4ms
memory: 22088kb