# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
889254 |
2023-12-19T09:11:52 Z |
kim |
Catfish Farm (IOI22_fish) |
C++17 |
|
923 ms |
152460 KB |
#include "fish.h"
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;
#define f first
#define s second
#define eb emplace_back
int N,M;
int X[300005],Y[300005],W[300005];
vector<pii> pos;
vector<pair<int,ll>> QS[300005];
vector<ll> dp[2];
int L[300005],R[300005];
ll qs(int x,int y){
auto itr=upper_bound(QS[x].begin(),QS[x].end(),pair<int,ll>(y,LLONG_MAX));
--itr;
return itr->s;
}
pii getRange(int x,int y1,int y2){
return pii(lower_bound(pos.begin()+L[x],pos.begin()+R[x]+1,pii(x,y1))-pos.begin(),
upper_bound(pos.begin()+L[x],pos.begin()+R[x]+1,pii(x,y2))-pos.begin()-1);
}
struct segment{
vector<segment> child;
int l,r,mid;
ll mx[3];
segment(int l_=0,int r_=0):l(l_),r(r_),mid(l+(r-l>>1)){
mx[0]=mx[1]=mx[2]=0;
}
void build(){
if(l==r) return;
child.eb(l,mid),child.eb(mid+1,r);
child[0].build(),child[1].build();
}
void upd(int i,int z,ll x){
if(l==r) return void(mx[z]=x);
if(i<=mid) child[0].upd(i,z,x);
else child[1].upd(i,z,x);
mx[z]=max(child[0].mx[z],child[1].mx[z]);
}
ll qr(int z,int l0,int r0){
if(l0<=l&&r<=r0) return mx[z];
if(l>r0||r<l0) return 0;
return max(child[0].qr(z,l0,r0),child[1].qr(z,l0,r0));
}
}t;
long long max_weights(int N_, int M_, std::vector<int> X_, std::vector<int> Y_,
std::vector<int> W_) {
N=N_,M=M_;
for(int i=1;i<=M;++i) X[i]=X_[i-1]+1,Y[i]=Y_[i-1]+1,W[i]=W_[i-1];
for(int i=1;i<=M;++i){
QS[X[i]].eb(Y[i],W[i]);
if(X[i]>1) pos.eb(X[i]-1,Y[i]);
if(X[i]<N) pos.eb(X[i]+1,Y[i]);
}
for(int i=1;i<=N;++i){
QS[i].eb(0,0);
sort(QS[i].begin(),QS[i].end());
for(int j=1;j<QS[i].size();++j) QS[i][j].s+=QS[i][j-1].s;
pos.eb(i,0);
}
pos.eb(0,0);
pos.eb(N+1,0);
QS[0].eb(0,0);
QS[N+1].eb(0,0);
sort(pos.begin(),pos.end());
pos.erase(unique(pos.begin(),pos.end()),pos.end());
for(int i=0;i<pos.size();++i){
if(!L[pos[i].f]) L[pos[i].f]=i;
R[pos[i].f]=i;
}
t=segment(0,pos.size()-1);
t.build();
dp[0]=dp[1]=vector<ll>(pos.size());
int l,r;
for(int i=1;i<pos.size();++i){
auto &[x,y]=pos[i];
tie(l,r)=getRange(x-1,0,y-1);
if(l<=r) dp[0][i]=t.qr(1,l,r)+qs(x-1,y);
if(i>3){
tie(l,r)=getRange(x-2,0,y-1);
if(l<=r) dp[0][i]=max(dp[0][i],t.qr(0,l,r)+qs(x-1,y));
}
tie(l,r)=getRange(x-1,y,N);
if(l<=r) dp[1][i]=t.qr(2,l,r)-qs(x,y);
if(i>2){
tie(l,r)=getRange(x-2,y,N);
if(l<=r) dp[1][i]=max(dp[1][i],t.qr(2,l,r));
}
if(i+1<pos.size()){
t.upd(i,0,max(dp[0][i],dp[1][i]));
t.upd(i,1,dp[0][i]-qs(x,y));
t.upd(i,2,max(dp[0][i],dp[1][i])+qs(x+1,y));
}
}
return dp[1].back();
// /*
// 0,1: qrz_1: dp[i][k][z]
// 2: qr0_2: dp[i][k][0]-qs[i][k]
// 3,4: qrz_3: dp[i][k][z]+qs[i+1][k]
// */
}
Compilation message
fish.cpp: In constructor 'segment::segment(int, int)':
fish.cpp:31:50: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
31 | segment(int l_=0,int r_=0):l(l_),r(r_),mid(l+(r-l>>1)){
| ~^~
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:65:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int j=1;j<QS[i].size();++j) QS[i][j].s+=QS[i][j-1].s;
| ~^~~~~~~~~~~~~
fish.cpp:74:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(int i=0;i<pos.size();++i){
| ~^~~~~~~~~~~
fish.cpp:83:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for(int i=1;i<pos.size();++i){
| ~^~~~~~~~~~~
fish.cpp:98:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
98 | if(i+1<pos.size()){
| ~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
45360 KB |
Output is correct |
2 |
Correct |
162 ms |
51392 KB |
Output is correct |
3 |
Correct |
71 ms |
30928 KB |
Output is correct |
4 |
Correct |
62 ms |
31060 KB |
Output is correct |
5 |
Correct |
677 ms |
142720 KB |
Output is correct |
6 |
Correct |
693 ms |
143840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
380 ms |
75948 KB |
Output is correct |
3 |
Correct |
454 ms |
88748 KB |
Output is correct |
4 |
Correct |
133 ms |
45252 KB |
Output is correct |
5 |
Correct |
182 ms |
51388 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
63 ms |
30928 KB |
Output is correct |
11 |
Correct |
63 ms |
31064 KB |
Output is correct |
12 |
Correct |
217 ms |
58632 KB |
Output is correct |
13 |
Correct |
264 ms |
69256 KB |
Output is correct |
14 |
Correct |
190 ms |
52172 KB |
Output is correct |
15 |
Correct |
236 ms |
56624 KB |
Output is correct |
16 |
Correct |
190 ms |
52148 KB |
Output is correct |
17 |
Correct |
244 ms |
56620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
31068 KB |
Output is correct |
2 |
Correct |
66 ms |
31084 KB |
Output is correct |
3 |
Correct |
129 ms |
41304 KB |
Output is correct |
4 |
Correct |
114 ms |
40128 KB |
Output is correct |
5 |
Correct |
195 ms |
56408 KB |
Output is correct |
6 |
Correct |
190 ms |
54096 KB |
Output is correct |
7 |
Correct |
194 ms |
55480 KB |
Output is correct |
8 |
Correct |
194 ms |
56124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
3 ms |
10844 KB |
Output is correct |
10 |
Correct |
6 ms |
11100 KB |
Output is correct |
11 |
Correct |
3 ms |
10844 KB |
Output is correct |
12 |
Correct |
4 ms |
10980 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
4 ms |
10844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
3 ms |
10844 KB |
Output is correct |
10 |
Correct |
6 ms |
11100 KB |
Output is correct |
11 |
Correct |
3 ms |
10844 KB |
Output is correct |
12 |
Correct |
4 ms |
10980 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
4 ms |
10844 KB |
Output is correct |
15 |
Correct |
2 ms |
10844 KB |
Output is correct |
16 |
Correct |
6 ms |
11100 KB |
Output is correct |
17 |
Correct |
88 ms |
22492 KB |
Output is correct |
18 |
Correct |
78 ms |
21768 KB |
Output is correct |
19 |
Correct |
81 ms |
21968 KB |
Output is correct |
20 |
Correct |
73 ms |
20820 KB |
Output is correct |
21 |
Correct |
72 ms |
20676 KB |
Output is correct |
22 |
Correct |
150 ms |
30800 KB |
Output is correct |
23 |
Correct |
22 ms |
13780 KB |
Output is correct |
24 |
Correct |
66 ms |
20180 KB |
Output is correct |
25 |
Correct |
5 ms |
11100 KB |
Output is correct |
26 |
Correct |
19 ms |
13672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
3 ms |
10844 KB |
Output is correct |
10 |
Correct |
6 ms |
11100 KB |
Output is correct |
11 |
Correct |
3 ms |
10844 KB |
Output is correct |
12 |
Correct |
4 ms |
10980 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
4 ms |
10844 KB |
Output is correct |
15 |
Correct |
2 ms |
10844 KB |
Output is correct |
16 |
Correct |
6 ms |
11100 KB |
Output is correct |
17 |
Correct |
88 ms |
22492 KB |
Output is correct |
18 |
Correct |
78 ms |
21768 KB |
Output is correct |
19 |
Correct |
81 ms |
21968 KB |
Output is correct |
20 |
Correct |
73 ms |
20820 KB |
Output is correct |
21 |
Correct |
72 ms |
20676 KB |
Output is correct |
22 |
Correct |
150 ms |
30800 KB |
Output is correct |
23 |
Correct |
22 ms |
13780 KB |
Output is correct |
24 |
Correct |
66 ms |
20180 KB |
Output is correct |
25 |
Correct |
5 ms |
11100 KB |
Output is correct |
26 |
Correct |
19 ms |
13672 KB |
Output is correct |
27 |
Correct |
9 ms |
12212 KB |
Output is correct |
28 |
Correct |
420 ms |
69572 KB |
Output is correct |
29 |
Correct |
658 ms |
107996 KB |
Output is correct |
30 |
Correct |
785 ms |
126680 KB |
Output is correct |
31 |
Correct |
763 ms |
127668 KB |
Output is correct |
32 |
Correct |
509 ms |
84384 KB |
Output is correct |
33 |
Correct |
799 ms |
129484 KB |
Output is correct |
34 |
Correct |
777 ms |
128432 KB |
Output is correct |
35 |
Correct |
256 ms |
51488 KB |
Output is correct |
36 |
Correct |
791 ms |
123112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
31068 KB |
Output is correct |
2 |
Correct |
66 ms |
31084 KB |
Output is correct |
3 |
Correct |
129 ms |
41304 KB |
Output is correct |
4 |
Correct |
114 ms |
40128 KB |
Output is correct |
5 |
Correct |
195 ms |
56408 KB |
Output is correct |
6 |
Correct |
190 ms |
54096 KB |
Output is correct |
7 |
Correct |
194 ms |
55480 KB |
Output is correct |
8 |
Correct |
194 ms |
56124 KB |
Output is correct |
9 |
Correct |
264 ms |
71264 KB |
Output is correct |
10 |
Correct |
163 ms |
44996 KB |
Output is correct |
11 |
Correct |
357 ms |
79840 KB |
Output is correct |
12 |
Correct |
2 ms |
10584 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10584 KB |
Output is correct |
16 |
Correct |
2 ms |
10588 KB |
Output is correct |
17 |
Correct |
2 ms |
10588 KB |
Output is correct |
18 |
Correct |
62 ms |
30928 KB |
Output is correct |
19 |
Correct |
61 ms |
30928 KB |
Output is correct |
20 |
Correct |
61 ms |
31068 KB |
Output is correct |
21 |
Correct |
61 ms |
30928 KB |
Output is correct |
22 |
Correct |
280 ms |
71128 KB |
Output is correct |
23 |
Correct |
483 ms |
102176 KB |
Output is correct |
24 |
Correct |
471 ms |
107616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
45360 KB |
Output is correct |
2 |
Correct |
162 ms |
51392 KB |
Output is correct |
3 |
Correct |
71 ms |
30928 KB |
Output is correct |
4 |
Correct |
62 ms |
31060 KB |
Output is correct |
5 |
Correct |
677 ms |
142720 KB |
Output is correct |
6 |
Correct |
693 ms |
143840 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
380 ms |
75948 KB |
Output is correct |
9 |
Correct |
454 ms |
88748 KB |
Output is correct |
10 |
Correct |
133 ms |
45252 KB |
Output is correct |
11 |
Correct |
182 ms |
51388 KB |
Output is correct |
12 |
Correct |
2 ms |
10588 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10588 KB |
Output is correct |
16 |
Correct |
63 ms |
30928 KB |
Output is correct |
17 |
Correct |
63 ms |
31064 KB |
Output is correct |
18 |
Correct |
217 ms |
58632 KB |
Output is correct |
19 |
Correct |
264 ms |
69256 KB |
Output is correct |
20 |
Correct |
190 ms |
52172 KB |
Output is correct |
21 |
Correct |
236 ms |
56624 KB |
Output is correct |
22 |
Correct |
190 ms |
52148 KB |
Output is correct |
23 |
Correct |
244 ms |
56620 KB |
Output is correct |
24 |
Correct |
64 ms |
31068 KB |
Output is correct |
25 |
Correct |
66 ms |
31084 KB |
Output is correct |
26 |
Correct |
129 ms |
41304 KB |
Output is correct |
27 |
Correct |
114 ms |
40128 KB |
Output is correct |
28 |
Correct |
195 ms |
56408 KB |
Output is correct |
29 |
Correct |
190 ms |
54096 KB |
Output is correct |
30 |
Correct |
194 ms |
55480 KB |
Output is correct |
31 |
Correct |
194 ms |
56124 KB |
Output is correct |
32 |
Correct |
2 ms |
10588 KB |
Output is correct |
33 |
Correct |
2 ms |
10588 KB |
Output is correct |
34 |
Correct |
2 ms |
10588 KB |
Output is correct |
35 |
Correct |
2 ms |
10588 KB |
Output is correct |
36 |
Correct |
2 ms |
10588 KB |
Output is correct |
37 |
Correct |
2 ms |
10588 KB |
Output is correct |
38 |
Correct |
2 ms |
10588 KB |
Output is correct |
39 |
Correct |
2 ms |
10588 KB |
Output is correct |
40 |
Correct |
3 ms |
10844 KB |
Output is correct |
41 |
Correct |
6 ms |
11100 KB |
Output is correct |
42 |
Correct |
3 ms |
10844 KB |
Output is correct |
43 |
Correct |
4 ms |
10980 KB |
Output is correct |
44 |
Correct |
2 ms |
10588 KB |
Output is correct |
45 |
Correct |
4 ms |
10844 KB |
Output is correct |
46 |
Correct |
2 ms |
10844 KB |
Output is correct |
47 |
Correct |
6 ms |
11100 KB |
Output is correct |
48 |
Correct |
88 ms |
22492 KB |
Output is correct |
49 |
Correct |
78 ms |
21768 KB |
Output is correct |
50 |
Correct |
81 ms |
21968 KB |
Output is correct |
51 |
Correct |
73 ms |
20820 KB |
Output is correct |
52 |
Correct |
72 ms |
20676 KB |
Output is correct |
53 |
Correct |
150 ms |
30800 KB |
Output is correct |
54 |
Correct |
22 ms |
13780 KB |
Output is correct |
55 |
Correct |
66 ms |
20180 KB |
Output is correct |
56 |
Correct |
5 ms |
11100 KB |
Output is correct |
57 |
Correct |
19 ms |
13672 KB |
Output is correct |
58 |
Correct |
9 ms |
12212 KB |
Output is correct |
59 |
Correct |
420 ms |
69572 KB |
Output is correct |
60 |
Correct |
658 ms |
107996 KB |
Output is correct |
61 |
Correct |
785 ms |
126680 KB |
Output is correct |
62 |
Correct |
763 ms |
127668 KB |
Output is correct |
63 |
Correct |
509 ms |
84384 KB |
Output is correct |
64 |
Correct |
799 ms |
129484 KB |
Output is correct |
65 |
Correct |
777 ms |
128432 KB |
Output is correct |
66 |
Correct |
256 ms |
51488 KB |
Output is correct |
67 |
Correct |
791 ms |
123112 KB |
Output is correct |
68 |
Correct |
264 ms |
71264 KB |
Output is correct |
69 |
Correct |
163 ms |
44996 KB |
Output is correct |
70 |
Correct |
357 ms |
79840 KB |
Output is correct |
71 |
Correct |
2 ms |
10584 KB |
Output is correct |
72 |
Correct |
2 ms |
10588 KB |
Output is correct |
73 |
Correct |
2 ms |
10588 KB |
Output is correct |
74 |
Correct |
2 ms |
10584 KB |
Output is correct |
75 |
Correct |
2 ms |
10588 KB |
Output is correct |
76 |
Correct |
2 ms |
10588 KB |
Output is correct |
77 |
Correct |
62 ms |
30928 KB |
Output is correct |
78 |
Correct |
61 ms |
30928 KB |
Output is correct |
79 |
Correct |
61 ms |
31068 KB |
Output is correct |
80 |
Correct |
61 ms |
30928 KB |
Output is correct |
81 |
Correct |
280 ms |
71128 KB |
Output is correct |
82 |
Correct |
483 ms |
102176 KB |
Output is correct |
83 |
Correct |
471 ms |
107616 KB |
Output is correct |
84 |
Correct |
907 ms |
142772 KB |
Output is correct |
85 |
Correct |
923 ms |
143192 KB |
Output is correct |
86 |
Correct |
736 ms |
149184 KB |
Output is correct |
87 |
Correct |
796 ms |
152244 KB |
Output is correct |
88 |
Correct |
3 ms |
10588 KB |
Output is correct |
89 |
Correct |
789 ms |
152460 KB |
Output is correct |
90 |
Correct |
714 ms |
136676 KB |
Output is correct |
91 |
Correct |
583 ms |
115084 KB |
Output is correct |