QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#266021#2342. Directing RainfallInfinityNS#WA 1128ms118624kbC++144.5kb2023-11-26 01:15:172023-11-26 01:15:19

Judging History

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

  • [2023-11-26 01:15:19]
  • 评测
  • 测评结果:WA
  • 用时:1128ms
  • 内存:118624kb
  • [2023-11-26 01:15:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ldb double
#define pb push_back

const int N=500050;
const int L=-1;
const int R=1e9+7;
const int inf=2*N;

int tme;
struct line{
    int x1,y1,x2,y2,i;

    line(){}

    ll Get() const {
        ll le=tme-x1;
        ll ri=x2-tme;
        return ri*y1+le*y2;
    }

    ll Stride() const {
        return x2-x1;
    }

    bool operator < (const line& other) const {
        return (__int128)Get() * other.Stride() < (__int128)other.Get() * Stride();
    }
}a[N];

vector<int> E[N];
int in[N];
void AddEdge(int u,int v){
    E[u].pb(v);
    in[v]++;
}

map<int,int> pos,neg;
void Add(int p,int x){
    //printf("Add %i: %i\n",p,x);
    if(pos.count(p)){
        pos[p]+=x;
        if(pos[p]<0){
            neg[p]=-pos[p];
        }
        if(pos[p]<=0){
            pos.erase(p);
        }
    }else if(neg.count(p)){
        neg[p]-=x;
        if(neg[p]<0){
            pos[p]=-neg[p];
        }
        if(neg[p]<=0){
            neg.erase(p);
        }
    }else{
        if(x>0){
            pos[p]=x;
        }else if(x<0){
            neg[p]=-x;
        }
    }
}

void AddLine(int i){
    //printf("Process line %i\n",i);
    int l=a[i].x1;
    int r=a[i].x2;
    if(a[i].y1 < a[i].y2){ // levo
        //printf("Left\n");
        while(true){
            auto it=neg.upper_bound(r);
            if(it==neg.begin())break;
            it--;
            if(it->first<=l)break;
            int p=it->first;
            int x=it->second;
            auto jt=pos.upper_bound(p);
            if(jt==pos.begin() || prev(jt)->first<=l){
                Add(l,-x);
                Add(p,x);
            }else{
                jt--;
                int mn=min(x,jt->second);
                Add(p,mn);
                Add(jt->first,-mn);
            }
        }
        Add(l+1,1);
        Add(r+1,-1);
    }else{
        //printf("Right\n");
        while(true){
            auto it=pos.lower_bound(l+1);
            if(it==pos.end())break;
            if(it->first>r)break;
            int p=it->first;
            int x=it->second;
            auto jt=neg.lower_bound(p+1);
            if(jt==neg.end() || jt->first>r){
                Add(r+1,x);
                Add(p,-x);
            }else{
                int mn=min(x,jt->second);
                Add(p,-mn);
                Add(jt->first,mn);
            }
        }
        Add(l,1);
        Add(r,-1);
    }
}

bool sec(int l1,int r1,int l2,int r2){
    return max(l1,l2)<=min(r1,r2);
}

int main(){
    int l,r,n;
    scanf("%i %i %i",&l,&r,&n);
    vector<pair<int,int>> evs;
    for(int i=1;i<=n;i++){
        scanf("%i %i %i %i",&a[i].x1,&a[i].y1,&a[i].x2,&a[i].y2);
        if(a[i].x1>a[i].x2){
            swap(a[i].x1,a[i].x2);
            swap(a[i].y1,a[i].y2);
        }
        a[i].i=i;
        evs.pb({a[i].x1,i});
        evs.pb({a[i].x2,-i});
    }
    sort(evs.begin(),evs.end());
    set<line> all;
    for(auto ev:evs){
        int i=abs(ev.second);
        tme=ev.first;
        if(ev.second>0){
            //printf("Insert %i\n",i);
            all.insert(a[i]);
            auto it=all.lower_bound(a[i]);
            if(next(it)!=all.end()){
                AddEdge(next(it)->i,it->i);
            }
            if(it!=all.begin()){
                AddEdge(it->i,prev(it)->i);
            }
        }else{
            //printf("Erase %i\n",i);
            auto it=all.lower_bound(a[i]);
            if(next(it)!=all.end() && it!=all.begin()){
                AddEdge(next(it)->i,prev(it)->i);
            }
            all.erase(a[i]);
        }
    }
    Add(L,inf);
    Add(l,-inf);
    Add(r+1,inf);
    Add(R,-inf);
    queue<int> q;
    for(int i=1;i<=n;i++){
        if(!in[i]){
            q.push(i);
        }
    }
    while(q.size()){
        int u=q.front();
        q.pop();
        AddLine(u);
        for(int v:E[u]){
            in[v]--;
            if(!in[v]){
                q.push(v);
            }
        }
    }

    vector<pair<int,int>> add;
    for(auto x:pos)add.pb({x.first,x.second});
    for(auto x:neg)add.pb({x.first,-x.second});
    sort(add.begin(),add.end());
    int last=L;
    int sum=0;
    int ans=inf;
    for(auto ev:add){
        int now=ev.first;
        //printf("[%i, %i] %i\n",last,now-1,sum);
        if(sec(last,now-1,l,r)){
            ans=min(ans,sum);
        }
        sum+=ev.second;
        last=now;
    }
    printf("%i\n",ans);
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 18136kb

Test #2:

score: 0
Accepted
time: 2ms
memory: 16092kb

Test #3:

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

Test #4:

score: 0
Accepted
time: 2ms
memory: 16088kb

Test #5:

score: 0
Accepted
time: 2ms
memory: 16364kb

Test #6:

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

Test #7:

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

Test #8:

score: 0
Accepted
time: 2ms
memory: 18128kb

Test #9:

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

Test #10:

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

Test #11:

score: 0
Accepted
time: 2ms
memory: 18148kb

Test #12:

score: 0
Accepted
time: 1128ms
memory: 118624kb

Test #13:

score: 0
Accepted
time: 4ms
memory: 18116kb

Test #14:

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

Test #15:

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

Test #16:

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

Test #17:

score: 0
Accepted
time: 2ms
memory: 18204kb

Test #18:

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

Test #19:

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

Test #20:

score: 0
Accepted
time: 3ms
memory: 18144kb

Test #21:

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

Test #22:

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

Test #23:

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

Test #24:

score: 0
Accepted
time: 2ms
memory: 18120kb

Test #25:

score: 0
Accepted
time: 2ms
memory: 18372kb

Test #26:

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

Test #27:

score: 0
Accepted
time: 2ms
memory: 18368kb

Test #28:

score: 0
Accepted
time: 2ms
memory: 18144kb

Test #29:

score: -100
Wrong Answer
time: 2ms
memory: 18144kb