QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#486033#4368. Oilucup-team3474WA 1406ms33664kbC++233.6kb2024-07-21 14:53:562024-07-21 14:53:56

Judging History

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

  • [2024-07-21 14:53:56]
  • 评测
  • 测评结果:WA
  • 用时:1406ms
  • 内存:33664kb
  • [2024-07-21 14:53:56]
  • 提交

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 val[3000000];
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];
        val[x1[i]+1000010]+=(x2[i]-x1[i]);
        val[x2[i]+1+1000010]-=(x2[i]-x1[i]);
        
    }
    for(int i=1;i<3000000;i++) val[i]+=val[i-1];
    for(int i=1;i<3000000;i++) ans=max(ans,val[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: 4ms
memory: 33276kb

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: 0
Accepted
time: 4ms
memory: 33512kb

input:

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

output:

25

result:

ok single line: '25'

Test #3:

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

input:

1
-100 180 20

output:

280

result:

ok single line: '280'

Test #4:

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

input:

1
-1000000 1000000 1

output:

2000000

result:

ok single line: '2000000'

Test #5:

score: 0
Accepted
time: 6ms
memory: 33320kb

input:

1
-1000000 1000000 1000000

output:

2000000

result:

ok single line: '2000000'

Test #6:

score: 0
Accepted
time: 7ms
memory: 33280kb

input:

1
-1000000 -999999 1000000

output:

1

result:

ok single line: '1'

Test #7:

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

input:

1
1000000 999999 1000000

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 12ms
memory: 33576kb

input:

2
-1000 0 200
1 1000 200

output:

1000

result:

ok single line: '1000'

Test #9:

score: 0
Accepted
time: 1406ms
memory: 33404kb

input:

1000
737368 429284 959063
-548693 513523 43074
243164 -465669 860567
422975 -244747 588631
-136535 -470055 501433
-580596 -269833 22422
476738 -448258 866889
358773 563858 950905
-923261 208187 66835
-295330 444422 360513
-903435 841952 491761
377801 520064 65247
479135 -307498 426574
-794533 -46924...

output:

490622362

result:

ok single line: '490622362'

Test #10:

score: 0
Accepted
time: 1404ms
memory: 33640kb

input:

1000
393505 133958 96751
942939 72421 396439
-822694 -718897 366172
-833366 91559 389785
28456 -507666 398767
-178646 616985 288351
465302 236829 106233
-911686 531549 436738
946908 -619546 27459
840101 -51671 27117
904596 -552691 993402
-379495 -968868 996117
-993434 826061 624577
390359 750548 209...

output:

474626777

result:

ok single line: '474626777'

Test #11:

score: 0
Accepted
time: 1402ms
memory: 33408kb

input:

1000
91153 -919136 629430
-928593 -340764 946503
-958781 151370 414466
776584 -865178 350581
266056 -678142 180528
855892 -61597 800115
-150759 821898 16625
286683 401612 387028
-104779 -495288 75284
-292434 725113 64163
925796 -886633 920311
-995416 275385 423913
-922152 395549 705834
138194 618689...

output:

482990936

result:

ok single line: '482990936'

Test #12:

score: 0
Accepted
time: 12ms
memory: 33284kb

input:

3
10 20 10
20 30 20
10 20 30

output:

30

result:

ok single line: '30'

Test #13:

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

input:

3
10 20 30
20 30 20
10 20 10

output:

30

result:

ok single line: '30'

Test #14:

score: 0
Accepted
time: 306ms
memory: 33664kb

input:

1000
-500 -499 3
-499 -498 4
-498 -497 3
-497 -496 4
-496 -495 3
-495 -494 4
-494 -493 3
-493 -492 4
-492 -491 3
-491 -490 4
-490 -489 3
-489 -488 4
-488 -487 3
-487 -486 4
-486 -485 3
-485 -484 4
-484 -483 3
-483 -482 4
-482 -481 3
-481 -480 4
-480 -479 3
-479 -478 4
-478 -477 3
-477 -476 4
-476 -4...

output:

4

result:

ok single line: '4'

Test #15:

score: 0
Accepted
time: 300ms
memory: 33360kb

input:

1000
-500 -499 3
-499 -498 4
-498 -497 3
-497 -496 4
-496 -495 3
-495 -494 4
-494 -493 3
-493 -492 4
-492 -491 3
-491 -490 4
-490 -489 3
-489 -488 4
-488 -487 3
-487 -486 4
-486 -485 3
-485 -484 4
-484 -483 3
-483 -482 4
-482 -481 3
-481 -480 4
-480 -479 3
-479 -478 4
-478 -477 3
-477 -476 4
-476 -4...

output:

4

result:

ok single line: '4'

Test #16:

score: -100
Wrong Answer
time: 264ms
memory: 33348kb

input:

500
885456 935548 893024
644787 -652783 650298
808938 947594 815852
432081 -622268 435774
142740 -169702 143960
856557 925094 863878
261261 -736938 263494
930033 956540 937982
417456 924584 421024
594945 978958 600030
893646 933174 901284
547677 775565 552358
883935 916485 891490
821457 984796 82847...

output:

182013933

result:

wrong answer 1st lines differ - expected: '244491195', found: '182013933'