#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#pragma GCC optimize(2)
vector<int>fishies[100010];
map<int,ll>fishiess[100010];
unordered_map<int,ll>dp[100010][2];
int N;
inline ll ones(int col,int len){
return (--fishiess[col].upper_bound(len))->second;
}
struct segtree{
ll mp[100100];
vector<int>v;
segtree(){
memset(mp,-9,sizeof mp);
}
void reset(){
for(auto i:v)
mp[i]=-1e18;
v.clear();
}
ll query(int pos){
ll ans=0;
pos++;
while(pos)
ans=max(ans,mp[pos]),
pos-=pos&-pos;
return ans;
}
void upd(int p,ll x){
p++;
while(p<100100)
v.push_back(p),
mp[p]=max(mp[p],x),
p+=p&-p;
}
};
struct a_data_type{
segtree Sec,First,Overal,Third;
inline ll sec(int pos){
return Sec.query(N-pos);
}
inline ll first(int pos){
return First.query(pos);
}
inline ll overal(int pos){
return Overal.query(N-pos);
}
inline ll third(int pos){
return Third.query(pos);
}
void init(int i) {
Overal.reset(),
First.reset(),
Sec.reset(),
Third.reset();
for(auto j:fishies[i]){
j--;
ll A=dp[i][0][j];
ll B=dp[i][1][j];
Overal.upd(N-j,max(A,B));
First.upd(j,max(A,B)-ones(i+1,j));
Sec.upd(N-j,A);
Third.upd(j,B-ones(i,j)-ones(i+1,j));
}
}
} likehell[2];
ll max_weights(int N_,int M,vector<int> X,vector<int> Y,vector<int> W) {
N=N_;
for(int i=0;i<M;i++)
fishies[X[i]+1].push_back(Y[i]+1),
fishiess[X[i]+1][Y[i]+1]=W[i];
for(int i=1;i<=N;i++){
fishiess[i][N+1];
fishiess[i][0];
auto it=++fishiess[i].begin();
while(it!=fishiess[i].end())
it->second+=prev(it)->second,it++;
}
for(int i=1;i<=N;i++)
fishies[i].push_back(1),
fishies[i].push_back(N+1);
fishiess[N+1][0];
for(auto i:fishies[1])
dp[1][1][i-1]=ones(2,i-1);
int b=0;
likehell[b].init(1);
for(int i=2;i<=N;i++){
for(auto rw:fishies[i]) {
ll cons=ones(i+1,rw-1)+ones(i-1,rw-1);
ll F=likehell[!b].first(rw-1);
ll S=likehell[!b].overal(rw)-ones(i-1,rw-1);
dp[i][1][rw-1]=cons+max(F,S);
}
for(auto rw2:fishies[i]){
ll cons=ones(i+1,rw2-1)+ones(i-1,rw2-1);
ll F=likehell[b].third(rw2-1);
ll S=likehell[b].overal(rw2);
dp[i][1][rw2-1]=max(dp[i][1][rw2-1],F+cons);
dp[i][0][rw2-1]=S-ones(i,rw2-1)-ones(i-1,rw2-1)+cons;
}
for(auto rw2:fishies[i]) {
ll K=likehell[b].sec(rw2-1)-ones(i,rw2-1);
dp[i][0][rw2-1]=max(dp[i][0][rw2-1],ones(i+1,rw2-1)+K);
}
b=!b;
likehell[b].init(i);
}
return likehell[b].overal(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
223 ms |
94620 KB |
Output is correct |
2 |
Correct |
237 ms |
106388 KB |
Output is correct |
3 |
Correct |
102 ms |
74576 KB |
Output is correct |
4 |
Correct |
120 ms |
74724 KB |
Output is correct |
5 |
Correct |
753 ms |
141604 KB |
Output is correct |
6 |
Correct |
486 ms |
121000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
24664 KB |
Output is correct |
2 |
Correct |
475 ms |
119936 KB |
Output is correct |
3 |
Correct |
640 ms |
138792 KB |
Output is correct |
4 |
Correct |
216 ms |
94796 KB |
Output is correct |
5 |
Correct |
233 ms |
106316 KB |
Output is correct |
6 |
Correct |
8 ms |
24664 KB |
Output is correct |
7 |
Correct |
8 ms |
24668 KB |
Output is correct |
8 |
Correct |
8 ms |
24668 KB |
Output is correct |
9 |
Correct |
9 ms |
24664 KB |
Output is correct |
10 |
Correct |
101 ms |
74704 KB |
Output is correct |
11 |
Correct |
119 ms |
74736 KB |
Output is correct |
12 |
Correct |
257 ms |
94668 KB |
Output is correct |
13 |
Correct |
303 ms |
106320 KB |
Output is correct |
14 |
Correct |
211 ms |
95380 KB |
Output is correct |
15 |
Correct |
284 ms |
104312 KB |
Output is correct |
16 |
Correct |
209 ms |
95248 KB |
Output is correct |
17 |
Correct |
246 ms |
104000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
118 ms |
74580 KB |
Output is correct |
2 |
Correct |
116 ms |
74576 KB |
Output is correct |
3 |
Correct |
142 ms |
74320 KB |
Output is correct |
4 |
Correct |
128 ms |
77652 KB |
Output is correct |
5 |
Correct |
204 ms |
83172 KB |
Output is correct |
6 |
Correct |
205 ms |
83280 KB |
Output is correct |
7 |
Correct |
233 ms |
83284 KB |
Output is correct |
8 |
Correct |
202 ms |
83236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
24668 KB |
Output is correct |
2 |
Correct |
11 ms |
24612 KB |
Output is correct |
3 |
Correct |
8 ms |
24664 KB |
Output is correct |
4 |
Correct |
9 ms |
24488 KB |
Output is correct |
5 |
Correct |
9 ms |
24664 KB |
Output is correct |
6 |
Correct |
8 ms |
24668 KB |
Output is correct |
7 |
Correct |
8 ms |
24716 KB |
Output is correct |
8 |
Correct |
9 ms |
24668 KB |
Output is correct |
9 |
Correct |
8 ms |
24668 KB |
Output is correct |
10 |
Correct |
11 ms |
25180 KB |
Output is correct |
11 |
Correct |
9 ms |
24668 KB |
Output is correct |
12 |
Correct |
9 ms |
24924 KB |
Output is correct |
13 |
Correct |
8 ms |
24668 KB |
Output is correct |
14 |
Correct |
9 ms |
24924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
24668 KB |
Output is correct |
2 |
Correct |
11 ms |
24612 KB |
Output is correct |
3 |
Correct |
8 ms |
24664 KB |
Output is correct |
4 |
Correct |
9 ms |
24488 KB |
Output is correct |
5 |
Correct |
9 ms |
24664 KB |
Output is correct |
6 |
Correct |
8 ms |
24668 KB |
Output is correct |
7 |
Correct |
8 ms |
24716 KB |
Output is correct |
8 |
Correct |
9 ms |
24668 KB |
Output is correct |
9 |
Correct |
8 ms |
24668 KB |
Output is correct |
10 |
Correct |
11 ms |
25180 KB |
Output is correct |
11 |
Correct |
9 ms |
24668 KB |
Output is correct |
12 |
Correct |
9 ms |
24924 KB |
Output is correct |
13 |
Correct |
8 ms |
24668 KB |
Output is correct |
14 |
Correct |
9 ms |
24924 KB |
Output is correct |
15 |
Correct |
8 ms |
24668 KB |
Output is correct |
16 |
Correct |
14 ms |
25016 KB |
Output is correct |
17 |
Correct |
72 ms |
32632 KB |
Output is correct |
18 |
Correct |
89 ms |
33360 KB |
Output is correct |
19 |
Correct |
68 ms |
32856 KB |
Output is correct |
20 |
Correct |
66 ms |
33108 KB |
Output is correct |
21 |
Correct |
67 ms |
32848 KB |
Output is correct |
22 |
Correct |
145 ms |
41304 KB |
Output is correct |
23 |
Correct |
18 ms |
26460 KB |
Output is correct |
24 |
Correct |
43 ms |
29940 KB |
Output is correct |
25 |
Correct |
9 ms |
24924 KB |
Output is correct |
26 |
Correct |
21 ms |
26204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
24668 KB |
Output is correct |
2 |
Correct |
11 ms |
24612 KB |
Output is correct |
3 |
Correct |
8 ms |
24664 KB |
Output is correct |
4 |
Correct |
9 ms |
24488 KB |
Output is correct |
5 |
Correct |
9 ms |
24664 KB |
Output is correct |
6 |
Correct |
8 ms |
24668 KB |
Output is correct |
7 |
Correct |
8 ms |
24716 KB |
Output is correct |
8 |
Correct |
9 ms |
24668 KB |
Output is correct |
9 |
Correct |
8 ms |
24668 KB |
Output is correct |
10 |
Correct |
11 ms |
25180 KB |
Output is correct |
11 |
Correct |
9 ms |
24668 KB |
Output is correct |
12 |
Correct |
9 ms |
24924 KB |
Output is correct |
13 |
Correct |
8 ms |
24668 KB |
Output is correct |
14 |
Correct |
9 ms |
24924 KB |
Output is correct |
15 |
Correct |
8 ms |
24668 KB |
Output is correct |
16 |
Correct |
14 ms |
25016 KB |
Output is correct |
17 |
Correct |
72 ms |
32632 KB |
Output is correct |
18 |
Correct |
89 ms |
33360 KB |
Output is correct |
19 |
Correct |
68 ms |
32856 KB |
Output is correct |
20 |
Correct |
66 ms |
33108 KB |
Output is correct |
21 |
Correct |
67 ms |
32848 KB |
Output is correct |
22 |
Correct |
145 ms |
41304 KB |
Output is correct |
23 |
Correct |
18 ms |
26460 KB |
Output is correct |
24 |
Correct |
43 ms |
29940 KB |
Output is correct |
25 |
Correct |
9 ms |
24924 KB |
Output is correct |
26 |
Correct |
21 ms |
26204 KB |
Output is correct |
27 |
Correct |
14 ms |
26456 KB |
Output is correct |
28 |
Correct |
387 ms |
64888 KB |
Output is correct |
29 |
Correct |
684 ms |
83412 KB |
Output is correct |
30 |
Correct |
441 ms |
77648 KB |
Output is correct |
31 |
Correct |
448 ms |
77748 KB |
Output is correct |
32 |
Correct |
566 ms |
81236 KB |
Output is correct |
33 |
Correct |
451 ms |
77640 KB |
Output is correct |
34 |
Correct |
483 ms |
77652 KB |
Output is correct |
35 |
Correct |
171 ms |
46164 KB |
Output is correct |
36 |
Correct |
557 ms |
80252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
118 ms |
74580 KB |
Output is correct |
2 |
Correct |
116 ms |
74576 KB |
Output is correct |
3 |
Correct |
142 ms |
74320 KB |
Output is correct |
4 |
Correct |
128 ms |
77652 KB |
Output is correct |
5 |
Correct |
204 ms |
83172 KB |
Output is correct |
6 |
Correct |
205 ms |
83280 KB |
Output is correct |
7 |
Correct |
233 ms |
83284 KB |
Output is correct |
8 |
Correct |
202 ms |
83236 KB |
Output is correct |
9 |
Correct |
201 ms |
89472 KB |
Output is correct |
10 |
Correct |
144 ms |
61264 KB |
Output is correct |
11 |
Correct |
307 ms |
98136 KB |
Output is correct |
12 |
Correct |
14 ms |
24628 KB |
Output is correct |
13 |
Correct |
8 ms |
24640 KB |
Output is correct |
14 |
Correct |
9 ms |
24668 KB |
Output is correct |
15 |
Correct |
10 ms |
24668 KB |
Output is correct |
16 |
Correct |
10 ms |
24480 KB |
Output is correct |
17 |
Correct |
11 ms |
24716 KB |
Output is correct |
18 |
Correct |
98 ms |
74580 KB |
Output is correct |
19 |
Correct |
103 ms |
74580 KB |
Output is correct |
20 |
Correct |
96 ms |
74580 KB |
Output is correct |
21 |
Correct |
150 ms |
74576 KB |
Output is correct |
22 |
Correct |
236 ms |
89428 KB |
Output is correct |
23 |
Correct |
354 ms |
104016 KB |
Output is correct |
24 |
Correct |
338 ms |
104400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
223 ms |
94620 KB |
Output is correct |
2 |
Correct |
237 ms |
106388 KB |
Output is correct |
3 |
Correct |
102 ms |
74576 KB |
Output is correct |
4 |
Correct |
120 ms |
74724 KB |
Output is correct |
5 |
Correct |
753 ms |
141604 KB |
Output is correct |
6 |
Correct |
486 ms |
121000 KB |
Output is correct |
7 |
Correct |
8 ms |
24664 KB |
Output is correct |
8 |
Correct |
475 ms |
119936 KB |
Output is correct |
9 |
Correct |
640 ms |
138792 KB |
Output is correct |
10 |
Correct |
216 ms |
94796 KB |
Output is correct |
11 |
Correct |
233 ms |
106316 KB |
Output is correct |
12 |
Correct |
8 ms |
24664 KB |
Output is correct |
13 |
Correct |
8 ms |
24668 KB |
Output is correct |
14 |
Correct |
8 ms |
24668 KB |
Output is correct |
15 |
Correct |
9 ms |
24664 KB |
Output is correct |
16 |
Correct |
101 ms |
74704 KB |
Output is correct |
17 |
Correct |
119 ms |
74736 KB |
Output is correct |
18 |
Correct |
257 ms |
94668 KB |
Output is correct |
19 |
Correct |
303 ms |
106320 KB |
Output is correct |
20 |
Correct |
211 ms |
95380 KB |
Output is correct |
21 |
Correct |
284 ms |
104312 KB |
Output is correct |
22 |
Correct |
209 ms |
95248 KB |
Output is correct |
23 |
Correct |
246 ms |
104000 KB |
Output is correct |
24 |
Correct |
118 ms |
74580 KB |
Output is correct |
25 |
Correct |
116 ms |
74576 KB |
Output is correct |
26 |
Correct |
142 ms |
74320 KB |
Output is correct |
27 |
Correct |
128 ms |
77652 KB |
Output is correct |
28 |
Correct |
204 ms |
83172 KB |
Output is correct |
29 |
Correct |
205 ms |
83280 KB |
Output is correct |
30 |
Correct |
233 ms |
83284 KB |
Output is correct |
31 |
Correct |
202 ms |
83236 KB |
Output is correct |
32 |
Correct |
9 ms |
24668 KB |
Output is correct |
33 |
Correct |
11 ms |
24612 KB |
Output is correct |
34 |
Correct |
8 ms |
24664 KB |
Output is correct |
35 |
Correct |
9 ms |
24488 KB |
Output is correct |
36 |
Correct |
9 ms |
24664 KB |
Output is correct |
37 |
Correct |
8 ms |
24668 KB |
Output is correct |
38 |
Correct |
8 ms |
24716 KB |
Output is correct |
39 |
Correct |
9 ms |
24668 KB |
Output is correct |
40 |
Correct |
8 ms |
24668 KB |
Output is correct |
41 |
Correct |
11 ms |
25180 KB |
Output is correct |
42 |
Correct |
9 ms |
24668 KB |
Output is correct |
43 |
Correct |
9 ms |
24924 KB |
Output is correct |
44 |
Correct |
8 ms |
24668 KB |
Output is correct |
45 |
Correct |
9 ms |
24924 KB |
Output is correct |
46 |
Correct |
8 ms |
24668 KB |
Output is correct |
47 |
Correct |
14 ms |
25016 KB |
Output is correct |
48 |
Correct |
72 ms |
32632 KB |
Output is correct |
49 |
Correct |
89 ms |
33360 KB |
Output is correct |
50 |
Correct |
68 ms |
32856 KB |
Output is correct |
51 |
Correct |
66 ms |
33108 KB |
Output is correct |
52 |
Correct |
67 ms |
32848 KB |
Output is correct |
53 |
Correct |
145 ms |
41304 KB |
Output is correct |
54 |
Correct |
18 ms |
26460 KB |
Output is correct |
55 |
Correct |
43 ms |
29940 KB |
Output is correct |
56 |
Correct |
9 ms |
24924 KB |
Output is correct |
57 |
Correct |
21 ms |
26204 KB |
Output is correct |
58 |
Correct |
14 ms |
26456 KB |
Output is correct |
59 |
Correct |
387 ms |
64888 KB |
Output is correct |
60 |
Correct |
684 ms |
83412 KB |
Output is correct |
61 |
Correct |
441 ms |
77648 KB |
Output is correct |
62 |
Correct |
448 ms |
77748 KB |
Output is correct |
63 |
Correct |
566 ms |
81236 KB |
Output is correct |
64 |
Correct |
451 ms |
77640 KB |
Output is correct |
65 |
Correct |
483 ms |
77652 KB |
Output is correct |
66 |
Correct |
171 ms |
46164 KB |
Output is correct |
67 |
Correct |
557 ms |
80252 KB |
Output is correct |
68 |
Correct |
201 ms |
89472 KB |
Output is correct |
69 |
Correct |
144 ms |
61264 KB |
Output is correct |
70 |
Correct |
307 ms |
98136 KB |
Output is correct |
71 |
Correct |
14 ms |
24628 KB |
Output is correct |
72 |
Correct |
8 ms |
24640 KB |
Output is correct |
73 |
Correct |
9 ms |
24668 KB |
Output is correct |
74 |
Correct |
10 ms |
24668 KB |
Output is correct |
75 |
Correct |
10 ms |
24480 KB |
Output is correct |
76 |
Correct |
11 ms |
24716 KB |
Output is correct |
77 |
Correct |
98 ms |
74580 KB |
Output is correct |
78 |
Correct |
103 ms |
74580 KB |
Output is correct |
79 |
Correct |
96 ms |
74580 KB |
Output is correct |
80 |
Correct |
150 ms |
74576 KB |
Output is correct |
81 |
Correct |
236 ms |
89428 KB |
Output is correct |
82 |
Correct |
354 ms |
104016 KB |
Output is correct |
83 |
Correct |
338 ms |
104400 KB |
Output is correct |
84 |
Execution timed out |
1040 ms |
126204 KB |
Time limit exceeded |
85 |
Halted |
0 ms |
0 KB |
- |