#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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;
void reset(){
for(auto i:v)
mp[i]=0;
v.clear();
}
ll query(int pos){
ll ans=0;
pos++;
while(pos)
ans=max(ans,mp[pos]),
pos-=pos&-pos;
return ans-(1ll<<50);
}
void upd(int p,ll x){
p++;
assert(p);
x+=1ll<<50;
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);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
231 ms |
92748 KB |
Output is correct |
2 |
Correct |
246 ms |
105228 KB |
Output is correct |
3 |
Correct |
132 ms |
68688 KB |
Output is correct |
4 |
Correct |
98 ms |
68724 KB |
Output is correct |
5 |
Correct |
718 ms |
144932 KB |
Output is correct |
6 |
Correct |
457 ms |
124500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
18524 KB |
Output is correct |
2 |
Correct |
456 ms |
122132 KB |
Output is correct |
3 |
Correct |
594 ms |
142376 KB |
Output is correct |
4 |
Correct |
190 ms |
92748 KB |
Output is correct |
5 |
Correct |
252 ms |
105160 KB |
Output is correct |
6 |
Correct |
7 ms |
18576 KB |
Output is correct |
7 |
Correct |
7 ms |
18536 KB |
Output is correct |
8 |
Correct |
7 ms |
18752 KB |
Output is correct |
9 |
Correct |
7 ms |
18520 KB |
Output is correct |
10 |
Correct |
97 ms |
68812 KB |
Output is correct |
11 |
Correct |
120 ms |
68708 KB |
Output is correct |
12 |
Correct |
230 ms |
92880 KB |
Output is correct |
13 |
Correct |
275 ms |
105076 KB |
Output is correct |
14 |
Correct |
209 ms |
93608 KB |
Output is correct |
15 |
Correct |
289 ms |
102748 KB |
Output is correct |
16 |
Correct |
210 ms |
93584 KB |
Output is correct |
17 |
Correct |
267 ms |
102720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
68776 KB |
Output is correct |
2 |
Correct |
109 ms |
68744 KB |
Output is correct |
3 |
Correct |
146 ms |
69204 KB |
Output is correct |
4 |
Correct |
158 ms |
72524 KB |
Output is correct |
5 |
Correct |
216 ms |
78960 KB |
Output is correct |
6 |
Correct |
171 ms |
78416 KB |
Output is correct |
7 |
Correct |
190 ms |
78992 KB |
Output is correct |
8 |
Correct |
178 ms |
78936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
18684 KB |
Output is correct |
2 |
Correct |
6 ms |
18524 KB |
Output is correct |
3 |
Correct |
7 ms |
18744 KB |
Output is correct |
4 |
Correct |
6 ms |
18524 KB |
Output is correct |
5 |
Correct |
7 ms |
18524 KB |
Output is correct |
6 |
Correct |
6 ms |
18656 KB |
Output is correct |
7 |
Correct |
6 ms |
18588 KB |
Output is correct |
8 |
Correct |
7 ms |
18524 KB |
Output is correct |
9 |
Correct |
7 ms |
18884 KB |
Output is correct |
10 |
Correct |
10 ms |
19292 KB |
Output is correct |
11 |
Correct |
8 ms |
18780 KB |
Output is correct |
12 |
Correct |
8 ms |
19036 KB |
Output is correct |
13 |
Correct |
7 ms |
18740 KB |
Output is correct |
14 |
Correct |
9 ms |
19032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
18684 KB |
Output is correct |
2 |
Correct |
6 ms |
18524 KB |
Output is correct |
3 |
Correct |
7 ms |
18744 KB |
Output is correct |
4 |
Correct |
6 ms |
18524 KB |
Output is correct |
5 |
Correct |
7 ms |
18524 KB |
Output is correct |
6 |
Correct |
6 ms |
18656 KB |
Output is correct |
7 |
Correct |
6 ms |
18588 KB |
Output is correct |
8 |
Correct |
7 ms |
18524 KB |
Output is correct |
9 |
Correct |
7 ms |
18884 KB |
Output is correct |
10 |
Correct |
10 ms |
19292 KB |
Output is correct |
11 |
Correct |
8 ms |
18780 KB |
Output is correct |
12 |
Correct |
8 ms |
19036 KB |
Output is correct |
13 |
Correct |
7 ms |
18740 KB |
Output is correct |
14 |
Correct |
9 ms |
19032 KB |
Output is correct |
15 |
Correct |
7 ms |
18804 KB |
Output is correct |
16 |
Correct |
9 ms |
19036 KB |
Output is correct |
17 |
Correct |
67 ms |
27476 KB |
Output is correct |
18 |
Correct |
73 ms |
28184 KB |
Output is correct |
19 |
Correct |
77 ms |
27728 KB |
Output is correct |
20 |
Correct |
78 ms |
27732 KB |
Output is correct |
21 |
Correct |
66 ms |
27712 KB |
Output is correct |
22 |
Correct |
149 ms |
36996 KB |
Output is correct |
23 |
Correct |
16 ms |
20572 KB |
Output is correct |
24 |
Correct |
44 ms |
24392 KB |
Output is correct |
25 |
Correct |
8 ms |
19032 KB |
Output is correct |
26 |
Correct |
16 ms |
20316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
18684 KB |
Output is correct |
2 |
Correct |
6 ms |
18524 KB |
Output is correct |
3 |
Correct |
7 ms |
18744 KB |
Output is correct |
4 |
Correct |
6 ms |
18524 KB |
Output is correct |
5 |
Correct |
7 ms |
18524 KB |
Output is correct |
6 |
Correct |
6 ms |
18656 KB |
Output is correct |
7 |
Correct |
6 ms |
18588 KB |
Output is correct |
8 |
Correct |
7 ms |
18524 KB |
Output is correct |
9 |
Correct |
7 ms |
18884 KB |
Output is correct |
10 |
Correct |
10 ms |
19292 KB |
Output is correct |
11 |
Correct |
8 ms |
18780 KB |
Output is correct |
12 |
Correct |
8 ms |
19036 KB |
Output is correct |
13 |
Correct |
7 ms |
18740 KB |
Output is correct |
14 |
Correct |
9 ms |
19032 KB |
Output is correct |
15 |
Correct |
7 ms |
18804 KB |
Output is correct |
16 |
Correct |
9 ms |
19036 KB |
Output is correct |
17 |
Correct |
67 ms |
27476 KB |
Output is correct |
18 |
Correct |
73 ms |
28184 KB |
Output is correct |
19 |
Correct |
77 ms |
27728 KB |
Output is correct |
20 |
Correct |
78 ms |
27732 KB |
Output is correct |
21 |
Correct |
66 ms |
27712 KB |
Output is correct |
22 |
Correct |
149 ms |
36996 KB |
Output is correct |
23 |
Correct |
16 ms |
20572 KB |
Output is correct |
24 |
Correct |
44 ms |
24392 KB |
Output is correct |
25 |
Correct |
8 ms |
19032 KB |
Output is correct |
26 |
Correct |
16 ms |
20316 KB |
Output is correct |
27 |
Correct |
11 ms |
20604 KB |
Output is correct |
28 |
Correct |
372 ms |
62788 KB |
Output is correct |
29 |
Correct |
684 ms |
82800 KB |
Output is correct |
30 |
Correct |
417 ms |
77404 KB |
Output is correct |
31 |
Correct |
444 ms |
77392 KB |
Output is correct |
32 |
Correct |
535 ms |
80464 KB |
Output is correct |
33 |
Correct |
437 ms |
77392 KB |
Output is correct |
34 |
Correct |
442 ms |
77444 KB |
Output is correct |
35 |
Correct |
148 ms |
42320 KB |
Output is correct |
36 |
Correct |
509 ms |
80080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
68776 KB |
Output is correct |
2 |
Correct |
109 ms |
68744 KB |
Output is correct |
3 |
Correct |
146 ms |
69204 KB |
Output is correct |
4 |
Correct |
158 ms |
72524 KB |
Output is correct |
5 |
Correct |
216 ms |
78960 KB |
Output is correct |
6 |
Correct |
171 ms |
78416 KB |
Output is correct |
7 |
Correct |
190 ms |
78992 KB |
Output is correct |
8 |
Correct |
178 ms |
78936 KB |
Output is correct |
9 |
Correct |
180 ms |
90960 KB |
Output is correct |
10 |
Correct |
125 ms |
57228 KB |
Output is correct |
11 |
Correct |
252 ms |
95572 KB |
Output is correct |
12 |
Correct |
7 ms |
18520 KB |
Output is correct |
13 |
Correct |
7 ms |
18608 KB |
Output is correct |
14 |
Correct |
7 ms |
18752 KB |
Output is correct |
15 |
Correct |
6 ms |
18524 KB |
Output is correct |
16 |
Correct |
8 ms |
18748 KB |
Output is correct |
17 |
Correct |
7 ms |
18524 KB |
Output is correct |
18 |
Correct |
95 ms |
68692 KB |
Output is correct |
19 |
Correct |
101 ms |
68932 KB |
Output is correct |
20 |
Correct |
96 ms |
68692 KB |
Output is correct |
21 |
Correct |
105 ms |
68692 KB |
Output is correct |
22 |
Correct |
235 ms |
91728 KB |
Output is correct |
23 |
Correct |
289 ms |
101456 KB |
Output is correct |
24 |
Correct |
267 ms |
102740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
231 ms |
92748 KB |
Output is correct |
2 |
Correct |
246 ms |
105228 KB |
Output is correct |
3 |
Correct |
132 ms |
68688 KB |
Output is correct |
4 |
Correct |
98 ms |
68724 KB |
Output is correct |
5 |
Correct |
718 ms |
144932 KB |
Output is correct |
6 |
Correct |
457 ms |
124500 KB |
Output is correct |
7 |
Correct |
6 ms |
18524 KB |
Output is correct |
8 |
Correct |
456 ms |
122132 KB |
Output is correct |
9 |
Correct |
594 ms |
142376 KB |
Output is correct |
10 |
Correct |
190 ms |
92748 KB |
Output is correct |
11 |
Correct |
252 ms |
105160 KB |
Output is correct |
12 |
Correct |
7 ms |
18576 KB |
Output is correct |
13 |
Correct |
7 ms |
18536 KB |
Output is correct |
14 |
Correct |
7 ms |
18752 KB |
Output is correct |
15 |
Correct |
7 ms |
18520 KB |
Output is correct |
16 |
Correct |
97 ms |
68812 KB |
Output is correct |
17 |
Correct |
120 ms |
68708 KB |
Output is correct |
18 |
Correct |
230 ms |
92880 KB |
Output is correct |
19 |
Correct |
275 ms |
105076 KB |
Output is correct |
20 |
Correct |
209 ms |
93608 KB |
Output is correct |
21 |
Correct |
289 ms |
102748 KB |
Output is correct |
22 |
Correct |
210 ms |
93584 KB |
Output is correct |
23 |
Correct |
267 ms |
102720 KB |
Output is correct |
24 |
Correct |
120 ms |
68776 KB |
Output is correct |
25 |
Correct |
109 ms |
68744 KB |
Output is correct |
26 |
Correct |
146 ms |
69204 KB |
Output is correct |
27 |
Correct |
158 ms |
72524 KB |
Output is correct |
28 |
Correct |
216 ms |
78960 KB |
Output is correct |
29 |
Correct |
171 ms |
78416 KB |
Output is correct |
30 |
Correct |
190 ms |
78992 KB |
Output is correct |
31 |
Correct |
178 ms |
78936 KB |
Output is correct |
32 |
Correct |
7 ms |
18684 KB |
Output is correct |
33 |
Correct |
6 ms |
18524 KB |
Output is correct |
34 |
Correct |
7 ms |
18744 KB |
Output is correct |
35 |
Correct |
6 ms |
18524 KB |
Output is correct |
36 |
Correct |
7 ms |
18524 KB |
Output is correct |
37 |
Correct |
6 ms |
18656 KB |
Output is correct |
38 |
Correct |
6 ms |
18588 KB |
Output is correct |
39 |
Correct |
7 ms |
18524 KB |
Output is correct |
40 |
Correct |
7 ms |
18884 KB |
Output is correct |
41 |
Correct |
10 ms |
19292 KB |
Output is correct |
42 |
Correct |
8 ms |
18780 KB |
Output is correct |
43 |
Correct |
8 ms |
19036 KB |
Output is correct |
44 |
Correct |
7 ms |
18740 KB |
Output is correct |
45 |
Correct |
9 ms |
19032 KB |
Output is correct |
46 |
Correct |
7 ms |
18804 KB |
Output is correct |
47 |
Correct |
9 ms |
19036 KB |
Output is correct |
48 |
Correct |
67 ms |
27476 KB |
Output is correct |
49 |
Correct |
73 ms |
28184 KB |
Output is correct |
50 |
Correct |
77 ms |
27728 KB |
Output is correct |
51 |
Correct |
78 ms |
27732 KB |
Output is correct |
52 |
Correct |
66 ms |
27712 KB |
Output is correct |
53 |
Correct |
149 ms |
36996 KB |
Output is correct |
54 |
Correct |
16 ms |
20572 KB |
Output is correct |
55 |
Correct |
44 ms |
24392 KB |
Output is correct |
56 |
Correct |
8 ms |
19032 KB |
Output is correct |
57 |
Correct |
16 ms |
20316 KB |
Output is correct |
58 |
Correct |
11 ms |
20604 KB |
Output is correct |
59 |
Correct |
372 ms |
62788 KB |
Output is correct |
60 |
Correct |
684 ms |
82800 KB |
Output is correct |
61 |
Correct |
417 ms |
77404 KB |
Output is correct |
62 |
Correct |
444 ms |
77392 KB |
Output is correct |
63 |
Correct |
535 ms |
80464 KB |
Output is correct |
64 |
Correct |
437 ms |
77392 KB |
Output is correct |
65 |
Correct |
442 ms |
77444 KB |
Output is correct |
66 |
Correct |
148 ms |
42320 KB |
Output is correct |
67 |
Correct |
509 ms |
80080 KB |
Output is correct |
68 |
Correct |
180 ms |
90960 KB |
Output is correct |
69 |
Correct |
125 ms |
57228 KB |
Output is correct |
70 |
Correct |
252 ms |
95572 KB |
Output is correct |
71 |
Correct |
7 ms |
18520 KB |
Output is correct |
72 |
Correct |
7 ms |
18608 KB |
Output is correct |
73 |
Correct |
7 ms |
18752 KB |
Output is correct |
74 |
Correct |
6 ms |
18524 KB |
Output is correct |
75 |
Correct |
8 ms |
18748 KB |
Output is correct |
76 |
Correct |
7 ms |
18524 KB |
Output is correct |
77 |
Correct |
95 ms |
68692 KB |
Output is correct |
78 |
Correct |
101 ms |
68932 KB |
Output is correct |
79 |
Correct |
96 ms |
68692 KB |
Output is correct |
80 |
Correct |
105 ms |
68692 KB |
Output is correct |
81 |
Correct |
235 ms |
91728 KB |
Output is correct |
82 |
Correct |
289 ms |
101456 KB |
Output is correct |
83 |
Correct |
267 ms |
102740 KB |
Output is correct |
84 |
Execution timed out |
1048 ms |
131616 KB |
Time limit exceeded |
85 |
Halted |
0 ms |
0 KB |
- |