QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#531927#2342. Directing RainfallSwarthmore#RE 0ms22324kbC++205.1kb2024-08-24 23:10:382024-08-24 23:10:38

Judging History

你现在查看的是最新测评结果

  • [2024-08-24 23:10:38]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:22324kb
  • [2024-08-24 23:10:38]
  • 提交

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;
    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: 22324kb

Test #2:

score: 0
Accepted
time: 0ms
memory: 21988kb

Test #3:

score: -100
Runtime Error