QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#518116#4561. Catfish Farmkimmoqt0 1457ms95088kbC++204.6kb2024-08-13 15:57:062024-08-13 15:57:07

Judging History

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

  • [2024-08-13 15:57:07]
  • 评测
  • 测评结果:0
  • 用时:1457ms
  • 内存:95088kb
  • [2024-08-13 15:57:06]
  • 提交

answer

#include "fish.h"

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

const int MX=1e6+5;

vector<int> col[MX];
ll dp[MX][2], pref[MX], dq[MX];

vector<int> Y;

int getPos(int c, int p) {
        if(p>=Y[col[c].back()]) return col[c].size();

        int l=0,r=col[c].size()-1,res=-1;
        while(l<=r) {
                int m=(l+r)/2;
                if(Y[col[c][m]]>=p) {
                        res=m,r=m-1;
                } else {
                        l=m+1;
                }
        }

        return res;
}

ll sum(ll c, ll x, ll y) {
        if(col[c].empty()) return 0;

        int l=getPos(c,x)-1, r=getPos(c,y+1)-1;
        if(r<0) return 0;

        ll res=pref[col[c][r]];
        if(l>=0) res-=pref[col[c][l]];
        return res;
}

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {

        set<pair<int,int>> pts;
        for(int i=0;i<M;i++) {
                pts.insert({X[i],Y[i]});
        }

        for(int i=0;i<M;i++) {
                if(X[i]>0 && !pts.count({X[i]-1,Y[i]})) {
                        pts.insert({X[i]-1,Y[i]});
                        X.push_back(X[i]-1);
                        Y.push_back(Y[i]);
                        W.push_back(0);
                }
                if(X[i]+1<N && !pts.count({X[i]+1,Y[i]})) {
                        pts.insert({X[i]+1,Y[i]});
                        X.push_back(X[i]+1);
                        Y.push_back(Y[i]);
                        W.push_back(0);
                }
        }

        M=X.size();
        for(int i=0;i<M;i++) {
                col[X[i]].push_back(i);
        }
        ::Y=Y;

        for(int i=0;i<N;i++) {
                sort(col[i].begin(),col[i].end(),[&](int i, int j){
                        return Y[i]<Y[j];
                });

                for(int j=0;j<col[i].size();j++) {
                        pref[col[i][j]]+=W[col[i][j]];
                        if(j>0) pref[col[i][j]]+=pref[col[i][j-1]];
                }
        }
        
        for(int i=0;i<N;i++) {
                if(i>=1) {
                        priority_queue<pair<ll,ll>> lf,rg;
                        for(auto j:col[i-1]) {
                                rg.push({
                                        max(dp[j][0],dp[j][1])+sum(i,-1,Y[j]),Y[j]});
                        }
                        int pt=0;
                        for(auto j:col[i]) {
                                while(rg.size() && rg.top().second<=Y[j]) rg.pop();

                                while(pt<col[i-1].size() && Y[col[i-1][pt]]<=Y[j]) {
                                        lf.push({dp[col[i-1][pt]][0]+sum(i-1,Y[col[i-1][pt]]+1,N),Y[j]});
                                        pt++;   
                                }

                                if(rg.size()) dp[j][1]=rg.top().first-sum(i,-1,Y[j]);
                                if(lf.size()) dp[j][0]=lf.top().first-sum(i-1,Y[j]+1,N); 

                                dp[j][0]=max(dp[j][0],sum(i-1,-1,Y[j]));
                        }
                }
                

                if(i>=2) {
                        priority_queue<pair<ll,ll>> lf,rg;
                        for(int j=0;j<col[i-2].size();j++) {
                                rg.push({max(dp[col[i-2][j]][0],dp[col[i-2][j]][1])+sum(i-1,-1,Y[col[i-2][j]]) 
                                        ,Y[col[i-2][j]]});
                        }
                        int pt=0;
                        for(auto j:col[i]) {
                                while(rg.size() && rg.top().second<=Y[j]) rg.pop();

                                while(pt<col[i-2].size() && Y[col[i-2][pt]]<=Y[j]) {
                                        lf.push({max(dp[col[i-2][pt]][0],dp[col[i-2][pt]][1]), 
                                                Y[col[i-2][pt]]});
                                        pt++;   
                                }

                                if(rg.size()) dp[j][0]=max(dp[j][0],rg.top().first);
                                if(lf.size()) dp[j][0]=max(dp[j][0],lf.top().first+sum(i-1,-1,Y[j]));

                                dp[j][0]=max(dp[j][0],dq[i-2]+sum(i-1,-1,Y[j]));
                                dq[i+1]=max(dq[i+1],dp[j][0]+sum(i+1,-1,Y[j]));
                        }
                }

                for(auto j:col[i]) {
                        dq[i+1]=max(dq[i+1],dp[j][0]+sum(i+1,-1,Y[j]));
                        dq[i+1]=max(dq[i+1],dp[j][1]+sum(i+1,-1,Y[j]));
                }
        }

        return *max_element(dq,dq+MX);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 149ms
memory: 23116kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
90000 80699
0 10792 55091480
0 36762 389250726
0 79267 706445371
0 76952 290301137
0 13444 69711795
0 68980 66221400
0 1695 703252611
0 36628 632571604
0 87676 264578012
0 79496 397448339
0 57929 447544332
0 35453 355374818
0 62449 686423696
0 45614 667165709...

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
40313272768926

result:

ok 3 lines

Test #2:

score: 3
Accepted
time: 199ms
memory: 27212kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 100000
0 64777 995289349
0 71596 893436841
0 577 789941184
0 74238 421759180
0 93045 833843112
0 17349 236016162
0 70194 646518626
0 59769 662584325
0 45550 706340730
0 8007 454213805
0 5460 328535742
0 47262 672607739
0 91960 166922115
0 26216 5441740...

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
49915093555295

result:

ok 3 lines

Test #3:

score: 3
Accepted
time: 3ms
memory: 3900kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 1
0 0 10082010

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
10082010

result:

ok 3 lines

Test #4:

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

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 1
0 99999 19122012

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
19122012

result:

ok 3 lines

Test #5:

score: 0
Wrong Answer
time: 1457ms
memory: 95088kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 300000
94880 38243 268662731
31482 11260 116303310
31482 29385 147398833
85804 78816 165663896
85804 50892 232441179
85804 52149 500231552
31482 15077 912836767
94880 13332 204098181
85804 4048 862989578
31482 94135 432330909
85804 30398 552396632
3702...

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
44945481875572

result:

wrong answer 3rd lines differ - expected: '149814460735479', found: '44945481875572'

Subtask #2:

score: 0
Wrong Answer

Test #7:

score: 0
Wrong Answer
time: 2ms
memory: 4120kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
3 2
0 0 1
1 1 1

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
1

result:

wrong answer 3rd lines differ - expected: '2', found: '1'

Subtask #3:

score: 0
Wrong Answer

Test #20:

score: 9
Accepted
time: 3ms
memory: 4116kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 1
0 0 10082010

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
10082010

result:

ok 3 lines

Test #21:

score: 9
Accepted
time: 3ms
memory: 4084kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 1
99999 0 882019

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
882019

result:

ok 3 lines

Test #22:

score: 0
Wrong Answer
time: 49ms
memory: 13244kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
90000 53444
40538 0 933021958
22736 0 403565340
52395 0 535014365
46488 0 818102149
19082 0 825246110
7712 0 581240932
30019 0 143288209
16519 0 206714026
8855 0 737518859
44939 0 63482743
40524 0 963968043
2663 0 953447256
25511 0 762455895
10794 0 880225092...

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
369591758422

result:

wrong answer 3rd lines differ - expected: '21261825233649', found: '369591758422'

Subtask #4:

score: 0
Wrong Answer

Test #28:

score: 0
Wrong Answer
time: 2ms
memory: 3820kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
4 3
2 2 1
0 0 1
1 1 1

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
2

result:

wrong answer 3rd lines differ - expected: '3', found: '2'

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Wrong Answer

Test #60:

score: 0
Wrong Answer
time: 210ms
memory: 38204kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 99999
31026 31026 1
42940 42940 1
69303 69303 1
90350 90350 1
77507 77507 1
87126 87126 1
17988 17988 1
5146 5146 1
63023 63023 1
27776 27776 1
6136 6136 1
82557 82557 1
24904 24904 1
21667 21667 1
67271 67271 1
80294 80294 1
81145 81145 1
47144 47144 ...

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
99998

result:

wrong answer 3rd lines differ - expected: '99999', found: '99998'

Subtask #8:

score: 0
Skipped

Dependency #1:

0%