#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
set<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{
unordered_map<int,ll>mp;
void reset(){mp.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++;
x+=1ll<<50;
while(p<N+2)
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);
}
set<int>prv;
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].insert(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].insert(1),
fishies[i].insert(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 |
Execution timed out |
1049 ms |
73824 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
20572 KB |
Output is correct |
2 |
Execution timed out |
1079 ms |
106284 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
297 ms |
77084 KB |
Output is correct |
2 |
Correct |
310 ms |
77128 KB |
Output is correct |
3 |
Correct |
355 ms |
76880 KB |
Output is correct |
4 |
Correct |
344 ms |
80720 KB |
Output is correct |
5 |
Correct |
367 ms |
86628 KB |
Output is correct |
6 |
Correct |
364 ms |
86356 KB |
Output is correct |
7 |
Correct |
366 ms |
86764 KB |
Output is correct |
8 |
Correct |
364 ms |
86732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
20572 KB |
Output is correct |
2 |
Correct |
8 ms |
20772 KB |
Output is correct |
3 |
Correct |
7 ms |
20788 KB |
Output is correct |
4 |
Correct |
7 ms |
20572 KB |
Output is correct |
5 |
Correct |
7 ms |
20664 KB |
Output is correct |
6 |
Correct |
7 ms |
20576 KB |
Output is correct |
7 |
Correct |
7 ms |
20572 KB |
Output is correct |
8 |
Correct |
7 ms |
20572 KB |
Output is correct |
9 |
Correct |
8 ms |
20828 KB |
Output is correct |
10 |
Correct |
9 ms |
21340 KB |
Output is correct |
11 |
Correct |
8 ms |
20844 KB |
Output is correct |
12 |
Correct |
9 ms |
21084 KB |
Output is correct |
13 |
Correct |
7 ms |
20828 KB |
Output is correct |
14 |
Correct |
8 ms |
21064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
20572 KB |
Output is correct |
2 |
Correct |
8 ms |
20772 KB |
Output is correct |
3 |
Correct |
7 ms |
20788 KB |
Output is correct |
4 |
Correct |
7 ms |
20572 KB |
Output is correct |
5 |
Correct |
7 ms |
20664 KB |
Output is correct |
6 |
Correct |
7 ms |
20576 KB |
Output is correct |
7 |
Correct |
7 ms |
20572 KB |
Output is correct |
8 |
Correct |
7 ms |
20572 KB |
Output is correct |
9 |
Correct |
8 ms |
20828 KB |
Output is correct |
10 |
Correct |
9 ms |
21340 KB |
Output is correct |
11 |
Correct |
8 ms |
20844 KB |
Output is correct |
12 |
Correct |
9 ms |
21084 KB |
Output is correct |
13 |
Correct |
7 ms |
20828 KB |
Output is correct |
14 |
Correct |
8 ms |
21064 KB |
Output is correct |
15 |
Correct |
8 ms |
20828 KB |
Output is correct |
16 |
Correct |
10 ms |
21148 KB |
Output is correct |
17 |
Correct |
76 ms |
31008 KB |
Output is correct |
18 |
Correct |
77 ms |
31632 KB |
Output is correct |
19 |
Correct |
73 ms |
31312 KB |
Output is correct |
20 |
Correct |
78 ms |
31348 KB |
Output is correct |
21 |
Correct |
73 ms |
31420 KB |
Output is correct |
22 |
Correct |
146 ms |
42068 KB |
Output is correct |
23 |
Correct |
22 ms |
22876 KB |
Output is correct |
24 |
Correct |
59 ms |
27728 KB |
Output is correct |
25 |
Correct |
9 ms |
21084 KB |
Output is correct |
26 |
Correct |
20 ms |
22876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
20572 KB |
Output is correct |
2 |
Correct |
8 ms |
20772 KB |
Output is correct |
3 |
Correct |
7 ms |
20788 KB |
Output is correct |
4 |
Correct |
7 ms |
20572 KB |
Output is correct |
5 |
Correct |
7 ms |
20664 KB |
Output is correct |
6 |
Correct |
7 ms |
20576 KB |
Output is correct |
7 |
Correct |
7 ms |
20572 KB |
Output is correct |
8 |
Correct |
7 ms |
20572 KB |
Output is correct |
9 |
Correct |
8 ms |
20828 KB |
Output is correct |
10 |
Correct |
9 ms |
21340 KB |
Output is correct |
11 |
Correct |
8 ms |
20844 KB |
Output is correct |
12 |
Correct |
9 ms |
21084 KB |
Output is correct |
13 |
Correct |
7 ms |
20828 KB |
Output is correct |
14 |
Correct |
8 ms |
21064 KB |
Output is correct |
15 |
Correct |
8 ms |
20828 KB |
Output is correct |
16 |
Correct |
10 ms |
21148 KB |
Output is correct |
17 |
Correct |
76 ms |
31008 KB |
Output is correct |
18 |
Correct |
77 ms |
31632 KB |
Output is correct |
19 |
Correct |
73 ms |
31312 KB |
Output is correct |
20 |
Correct |
78 ms |
31348 KB |
Output is correct |
21 |
Correct |
73 ms |
31420 KB |
Output is correct |
22 |
Correct |
146 ms |
42068 KB |
Output is correct |
23 |
Correct |
22 ms |
22876 KB |
Output is correct |
24 |
Correct |
59 ms |
27728 KB |
Output is correct |
25 |
Correct |
9 ms |
21084 KB |
Output is correct |
26 |
Correct |
20 ms |
22876 KB |
Output is correct |
27 |
Correct |
20 ms |
22876 KB |
Output is correct |
28 |
Correct |
476 ms |
71844 KB |
Output is correct |
29 |
Correct |
738 ms |
95000 KB |
Output is correct |
30 |
Correct |
749 ms |
89680 KB |
Output is correct |
31 |
Correct |
770 ms |
89684 KB |
Output is correct |
32 |
Correct |
576 ms |
91984 KB |
Output is correct |
33 |
Correct |
798 ms |
89684 KB |
Output is correct |
34 |
Correct |
801 ms |
89684 KB |
Output is correct |
35 |
Correct |
207 ms |
48236 KB |
Output is correct |
36 |
Correct |
739 ms |
91692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
297 ms |
77084 KB |
Output is correct |
2 |
Correct |
310 ms |
77128 KB |
Output is correct |
3 |
Correct |
355 ms |
76880 KB |
Output is correct |
4 |
Correct |
344 ms |
80720 KB |
Output is correct |
5 |
Correct |
367 ms |
86628 KB |
Output is correct |
6 |
Correct |
364 ms |
86356 KB |
Output is correct |
7 |
Correct |
366 ms |
86764 KB |
Output is correct |
8 |
Correct |
364 ms |
86732 KB |
Output is correct |
9 |
Correct |
595 ms |
97556 KB |
Output is correct |
10 |
Correct |
233 ms |
64060 KB |
Output is correct |
11 |
Correct |
524 ms |
107324 KB |
Output is correct |
12 |
Correct |
8 ms |
20572 KB |
Output is correct |
13 |
Correct |
7 ms |
20792 KB |
Output is correct |
14 |
Correct |
7 ms |
20572 KB |
Output is correct |
15 |
Correct |
7 ms |
20572 KB |
Output is correct |
16 |
Correct |
7 ms |
20572 KB |
Output is correct |
17 |
Correct |
7 ms |
20572 KB |
Output is correct |
18 |
Correct |
321 ms |
76916 KB |
Output is correct |
19 |
Correct |
303 ms |
77136 KB |
Output is correct |
20 |
Correct |
295 ms |
77132 KB |
Output is correct |
21 |
Correct |
293 ms |
77140 KB |
Output is correct |
22 |
Correct |
627 ms |
97872 KB |
Output is correct |
23 |
Correct |
616 ms |
117584 KB |
Output is correct |
24 |
Correct |
743 ms |
118612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1049 ms |
73824 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |