QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#486032#4368. Oilucup-team3474WA 1ms10092kbC++233.4kb2024-07-21 14:51:442024-07-21 14:51:44

Judging History

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

  • [2024-07-21 14:51:44]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:10092kb
  • [2024-07-21 14:51:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll N=1919810,INF=1e18;
ll n;
ll ans;

ll x1[N],x2[N],y[N];
ll s[10010];
ll cnt[N];
ll gcd(ll x,ll y){
    if(!y) return x;
    return gcd(y,x%y);
}

typedef struct{
    ll first,second;
}PII;

bool operator<(const PII&a,const PII &b){
    return a.second*b.first<a.first*b.second;
    
}


bool operator>(const PII&a,const PII &b){
    return a.second*b.first>a.first*b.second;
    
}

bool operator==(const PII&a,const PII &b){
    return a.second*b.first==a.first*b.second;
    
}

bool cmp(const PII&a,const PII &b){
    return a.first*b.second<a.second*b.first;
    
}

void gao(ll x0,ll y0,ll id){
    memset(s,0,sizeof s);
    vector<PII> segs;
    map<PII,ll> mp;
    ll res=0;
    segs.push_back({-1,0});
    segs.push_back({1,0});
    for(int i=1;i<=n;i++){
        if(i==id) continue;
        if(y[i]==y0) continue;
        PII u1,u2;
        ll gg=gcd(abs(y[i]-y0),abs(x1[i]-x0));
        ll flag=1;
        if(x1[i]-x0<0) flag=-1;
        u1={flag*(y[i]-y0)/gg,flag*(x1[i]-x0)/gg};
        segs.push_back(u1);
        flag=1;
        if(x2[i]-x0<0) flag=-1;
        gg=gcd(abs(y[i]-y0),abs(x2[i]-x0));
        u2={flag*(y[i]-y0)/gg,flag*(x2[i]-x0)/gg};
        segs.push_back(u2);
    }
    sort(segs.begin(),segs.end(),cmp);
    segs.erase(unique(segs.begin(),segs.end()),segs.end());
    for(int i=0;i<segs.size();i++){
        //cout<<segs[i].first<<" "<<segs[i].second<<endl;
        mp[segs[i]]=i+1;
        
    }
    for(int i=1;i<=n;i++){
        if(i==id) continue;
        if(y[i]==y0) continue;
       PII u1,u2;
        ll gg=gcd(abs(y[i]-y0),abs(x1[i]-x0));
        ll flag=1;
        if(x1[i]-x0<0) flag=-1;
        u1={flag*(y[i]-y0)/gg,flag*(x1[i]-x0)/gg};
        segs.push_back(u1);
        flag=1;
        if(x2[i]-x0<0) flag=-1;
        gg=gcd(abs(y[i]-y0),abs(x2[i]-x0));
        u2={flag*(y[i]-y0)/gg,flag*(x2[i]-x0)/gg};
        segs.push_back(u2);
       ll m1=mp[u1],m2=mp[u2];
       ll del=x2[i]-x1[i];
       if(y[i]>y0){
           if(m1<m2){
               s[m1]-=del;
               s[mp[{-1,0}]]+=del;
               s[m2]+=del;
               s[mp[{1,0}]]-=del;
           }else{
               s[m1]-=del;
               s[m2]+=del;
           }
       }else{
           if(m1>m2){
               s[m1]+=del;
               s[mp[{1,0}]]-=del;
               s[m2]-=del;
               s[mp[{-1,0}]]+=del;
           }else{
               s[m1]+=del;
               s[m2]-=del;
           }
       }
    }
    for(int i=1;i<=segs.size();i++){
        s[i]+=s[i-1];
        //cout<<s[i]<<" ";
        res=max(s[i],res);
    }
   // cout<<endl;
    // cout<<res<<" "<<x0<<" "<<y0<<" "<<id<<endl;
    // cout<<x2[id]<<" "<<x1[id]<<" "<<res<<endl;
    ans=max(ans,x2[id]-x1[id]+res);
    
}

int main() {
    cin>>n;
    ll sb=0;
    // map<ll,ll> mp;
    for(int i=1;i<=n;i++){
        scanf("%lld%lld%lld",&x1[i],&x2[i],&y[i]);
        
        sb=max(sb,y[i]);
        // if(x1[i]>x2[i]) swap(x1[i],x2[i]);
        // cnt[y[i]]+=x2[i]-x1[i];
        // for(int j=x1[i];j<=x2[i];j++) mp[j]+=x2[i]-x1[i];
    }
    // for(int i=1;i<=n;i++) y[i]=sb-y[i];
    // for(int i=1;i<N;i++) ans=max(ans,mp[i]);
    for(int i=1;i<=n;i++){
        gao(x1[i],y[i],i);
        gao(x2[i],y[i],i);
    }
    cout<<ans<<endl;
	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 10092kb

input:

5
100 180 20
30 60 30
70 110 40
10 40 50
0 80 70

output:

200

result:

ok single line: '200'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 10088kb

input:

3
50 60 10
-42 -42 20
25 0 10

output:

10

result:

wrong answer 1st lines differ - expected: '25', found: '10'