#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int,int>
#define fi first
#define se second
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
struct node{
int s,e,m;
int val=0,lazy=0;
node *l,*r;
node (int _s,int _e){
s=_s,e=_e,m=s+e>>1;
if (s!=e){
l=new node(s,m);
r=new node(m+1,e);
}
}
void propo(){
if (lazy==0) return;
val+=lazy;
if (s!=e){
l->lazy+=lazy;
r->lazy+=lazy;
}
lazy=0;
}
void update(int i,int j,int k){
if (s==i && e==j) lazy+=k;
else{
if (j<=m) l->update(i,j,k);
else if (m<i) r->update(i,j,k);
else l->update(i,m,k),r->update(m+1,j,k);
l->propo(),r->propo();
val=max(l->val,r->val);
}
}
} *root;
int n,m;
vector<ii> arr[100005];
vector<int> pos[100005];
vector<int> w[100005];
vector<int> memo[2][2];
int max_weights(signed N, signed M, vector<signed> X, vector<signed> Y,
vector<signed> W) {
n=N,m=M;
rep(x,0,m) arr[X[x]+1].pub({Y[x],W[x]});
rep(x,0,n+2){
if (x==0 || x==n+1) arr[x].pub({0,0});
else arr[x].pub({n+1,0});
sort(all(arr[x]));
for (auto [a,b]:arr[x]){
pos[x].pub(a);
w[x].pub(b);
}
}
int a=0,b=1;
memo[a][0]=memo[a][1]={0};
rep(idx,1,n+2){
int ss1=sz(pos[idx-1]),ss2=sz(pos[idx]);
memo[b][0]=vector<int>(ss2,0); //contribution counted
memo[b][1]=vector<int>(ss2,0); //contribution not counted
rep(i,0,2) rep(j,0,2){
root=new node(0,ss1-1);
rep(x,0,ss1) root->update(x,x,memo[a][i][x]);
rep(y,0,sz(pos[idx])) if (j==0){
int z=ub(all(pos[idx-1]),pos[idx][y])-pos[idx-1].begin();
if (z<ss1) root->update(z,ss1-1,w[idx][y]);
}
int z=0;
rep(y,0,sz(pos[idx])){
if (i==1){
while (z<sz(pos[idx-1]) && pos[idx-1][z]<pos[idx][y]){
root->update(0,z,w[idx-1][z]);
z++;
}
}
root->propo();
memo[b][j][y]=max(memo[b][j][y],root->val);
if (j==0){
int z=ub(all(pos[idx-1]),pos[idx][y])-pos[idx-1].begin();
if (z<ss1) root->update(z,ss1-1,-w[idx][y]);
}
}
}
swap(a,b);
//cout<<"idx: "<<idx<<endl;
//for (auto it:memo[a][0]) cout<<it<<" "; cout<<endl;
//for (auto it:memo[a][1]) cout<<it<<" "; cout<<endl;
}
return memo[a][0][0];
}
Compilation message
fish.cpp: In constructor 'node::node(long long int, long long int)':
fish.cpp:30:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
30 | s=_s,e=_e,m=s+e>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
177 ms |
83472 KB |
Output is correct |
2 |
Correct |
216 ms |
97752 KB |
Output is correct |
3 |
Correct |
81 ms |
41676 KB |
Output is correct |
4 |
Correct |
57 ms |
41696 KB |
Output is correct |
5 |
Correct |
585 ms |
208972 KB |
Output is correct |
6 |
Correct |
447 ms |
212076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
Output is correct |
2 |
Correct |
414 ms |
128496 KB |
Output is correct |
3 |
Correct |
492 ms |
153312 KB |
Output is correct |
4 |
Correct |
182 ms |
83380 KB |
Output is correct |
5 |
Correct |
223 ms |
97672 KB |
Output is correct |
6 |
Correct |
6 ms |
7252 KB |
Output is correct |
7 |
Correct |
4 ms |
7252 KB |
Output is correct |
8 |
Correct |
5 ms |
7252 KB |
Output is correct |
9 |
Correct |
6 ms |
7352 KB |
Output is correct |
10 |
Correct |
69 ms |
41728 KB |
Output is correct |
11 |
Correct |
57 ms |
41744 KB |
Output is correct |
12 |
Correct |
188 ms |
83644 KB |
Output is correct |
13 |
Correct |
211 ms |
97648 KB |
Output is correct |
14 |
Correct |
207 ms |
83752 KB |
Output is correct |
15 |
Correct |
259 ms |
92252 KB |
Output is correct |
16 |
Correct |
219 ms |
83852 KB |
Output is correct |
17 |
Correct |
315 ms |
92268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
41692 KB |
Output is correct |
2 |
Correct |
67 ms |
41708 KB |
Output is correct |
3 |
Correct |
131 ms |
67408 KB |
Output is correct |
4 |
Correct |
133 ms |
61588 KB |
Output is correct |
5 |
Correct |
181 ms |
95868 KB |
Output is correct |
6 |
Correct |
246 ms |
96128 KB |
Output is correct |
7 |
Correct |
197 ms |
96300 KB |
Output is correct |
8 |
Correct |
177 ms |
96272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7236 KB |
Output is correct |
2 |
Correct |
5 ms |
7252 KB |
Output is correct |
3 |
Correct |
4 ms |
7300 KB |
Output is correct |
4 |
Correct |
6 ms |
7252 KB |
Output is correct |
5 |
Correct |
4 ms |
7296 KB |
Output is correct |
6 |
Correct |
5 ms |
7252 KB |
Output is correct |
7 |
Correct |
5 ms |
7252 KB |
Output is correct |
8 |
Correct |
6 ms |
7252 KB |
Output is correct |
9 |
Correct |
6 ms |
7644 KB |
Output is correct |
10 |
Correct |
9 ms |
8788 KB |
Output is correct |
11 |
Correct |
6 ms |
7764 KB |
Output is correct |
12 |
Correct |
6 ms |
8020 KB |
Output is correct |
13 |
Correct |
4 ms |
7380 KB |
Output is correct |
14 |
Correct |
5 ms |
7892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7236 KB |
Output is correct |
2 |
Correct |
5 ms |
7252 KB |
Output is correct |
3 |
Correct |
4 ms |
7300 KB |
Output is correct |
4 |
Correct |
6 ms |
7252 KB |
Output is correct |
5 |
Correct |
4 ms |
7296 KB |
Output is correct |
6 |
Correct |
5 ms |
7252 KB |
Output is correct |
7 |
Correct |
5 ms |
7252 KB |
Output is correct |
8 |
Correct |
6 ms |
7252 KB |
Output is correct |
9 |
Correct |
6 ms |
7644 KB |
Output is correct |
10 |
Correct |
9 ms |
8788 KB |
Output is correct |
11 |
Correct |
6 ms |
7764 KB |
Output is correct |
12 |
Correct |
6 ms |
8020 KB |
Output is correct |
13 |
Correct |
4 ms |
7380 KB |
Output is correct |
14 |
Correct |
5 ms |
7892 KB |
Output is correct |
15 |
Correct |
6 ms |
7508 KB |
Output is correct |
16 |
Correct |
7 ms |
8532 KB |
Output is correct |
17 |
Correct |
81 ms |
32940 KB |
Output is correct |
18 |
Correct |
89 ms |
33608 KB |
Output is correct |
19 |
Correct |
89 ms |
33376 KB |
Output is correct |
20 |
Correct |
96 ms |
33420 KB |
Output is correct |
21 |
Correct |
77 ms |
33384 KB |
Output is correct |
22 |
Correct |
157 ms |
59452 KB |
Output is correct |
23 |
Correct |
19 ms |
12504 KB |
Output is correct |
24 |
Correct |
63 ms |
24324 KB |
Output is correct |
25 |
Correct |
7 ms |
8020 KB |
Output is correct |
26 |
Correct |
23 ms |
12140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7236 KB |
Output is correct |
2 |
Correct |
5 ms |
7252 KB |
Output is correct |
3 |
Correct |
4 ms |
7300 KB |
Output is correct |
4 |
Correct |
6 ms |
7252 KB |
Output is correct |
5 |
Correct |
4 ms |
7296 KB |
Output is correct |
6 |
Correct |
5 ms |
7252 KB |
Output is correct |
7 |
Correct |
5 ms |
7252 KB |
Output is correct |
8 |
Correct |
6 ms |
7252 KB |
Output is correct |
9 |
Correct |
6 ms |
7644 KB |
Output is correct |
10 |
Correct |
9 ms |
8788 KB |
Output is correct |
11 |
Correct |
6 ms |
7764 KB |
Output is correct |
12 |
Correct |
6 ms |
8020 KB |
Output is correct |
13 |
Correct |
4 ms |
7380 KB |
Output is correct |
14 |
Correct |
5 ms |
7892 KB |
Output is correct |
15 |
Correct |
6 ms |
7508 KB |
Output is correct |
16 |
Correct |
7 ms |
8532 KB |
Output is correct |
17 |
Correct |
81 ms |
32940 KB |
Output is correct |
18 |
Correct |
89 ms |
33608 KB |
Output is correct |
19 |
Correct |
89 ms |
33376 KB |
Output is correct |
20 |
Correct |
96 ms |
33420 KB |
Output is correct |
21 |
Correct |
77 ms |
33384 KB |
Output is correct |
22 |
Correct |
157 ms |
59452 KB |
Output is correct |
23 |
Correct |
19 ms |
12504 KB |
Output is correct |
24 |
Correct |
63 ms |
24324 KB |
Output is correct |
25 |
Correct |
7 ms |
8020 KB |
Output is correct |
26 |
Correct |
23 ms |
12140 KB |
Output is correct |
27 |
Correct |
9 ms |
9928 KB |
Output is correct |
28 |
Correct |
444 ms |
133688 KB |
Output is correct |
29 |
Correct |
739 ms |
180264 KB |
Output is correct |
30 |
Correct |
486 ms |
180064 KB |
Output is correct |
31 |
Correct |
563 ms |
180144 KB |
Output is correct |
32 |
Correct |
601 ms |
182896 KB |
Output is correct |
33 |
Correct |
471 ms |
179728 KB |
Output is correct |
34 |
Correct |
469 ms |
179404 KB |
Output is correct |
35 |
Correct |
203 ms |
76036 KB |
Output is correct |
36 |
Correct |
629 ms |
182360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
41692 KB |
Output is correct |
2 |
Correct |
67 ms |
41708 KB |
Output is correct |
3 |
Correct |
131 ms |
67408 KB |
Output is correct |
4 |
Correct |
133 ms |
61588 KB |
Output is correct |
5 |
Correct |
181 ms |
95868 KB |
Output is correct |
6 |
Correct |
246 ms |
96128 KB |
Output is correct |
7 |
Correct |
197 ms |
96300 KB |
Output is correct |
8 |
Correct |
177 ms |
96272 KB |
Output is correct |
9 |
Correct |
225 ms |
95872 KB |
Output is correct |
10 |
Correct |
175 ms |
81136 KB |
Output is correct |
11 |
Correct |
343 ms |
155160 KB |
Output is correct |
12 |
Correct |
4 ms |
7252 KB |
Output is correct |
13 |
Correct |
4 ms |
7356 KB |
Output is correct |
14 |
Correct |
4 ms |
7252 KB |
Output is correct |
15 |
Correct |
5 ms |
7252 KB |
Output is correct |
16 |
Correct |
5 ms |
7252 KB |
Output is correct |
17 |
Correct |
5 ms |
7252 KB |
Output is correct |
18 |
Correct |
57 ms |
41776 KB |
Output is correct |
19 |
Correct |
65 ms |
41668 KB |
Output is correct |
20 |
Correct |
54 ms |
41776 KB |
Output is correct |
21 |
Correct |
55 ms |
41664 KB |
Output is correct |
22 |
Correct |
265 ms |
97324 KB |
Output is correct |
23 |
Correct |
328 ms |
155196 KB |
Output is correct |
24 |
Correct |
339 ms |
156340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
177 ms |
83472 KB |
Output is correct |
2 |
Correct |
216 ms |
97752 KB |
Output is correct |
3 |
Correct |
81 ms |
41676 KB |
Output is correct |
4 |
Correct |
57 ms |
41696 KB |
Output is correct |
5 |
Correct |
585 ms |
208972 KB |
Output is correct |
6 |
Correct |
447 ms |
212076 KB |
Output is correct |
7 |
Correct |
4 ms |
7252 KB |
Output is correct |
8 |
Correct |
414 ms |
128496 KB |
Output is correct |
9 |
Correct |
492 ms |
153312 KB |
Output is correct |
10 |
Correct |
182 ms |
83380 KB |
Output is correct |
11 |
Correct |
223 ms |
97672 KB |
Output is correct |
12 |
Correct |
6 ms |
7252 KB |
Output is correct |
13 |
Correct |
4 ms |
7252 KB |
Output is correct |
14 |
Correct |
5 ms |
7252 KB |
Output is correct |
15 |
Correct |
6 ms |
7352 KB |
Output is correct |
16 |
Correct |
69 ms |
41728 KB |
Output is correct |
17 |
Correct |
57 ms |
41744 KB |
Output is correct |
18 |
Correct |
188 ms |
83644 KB |
Output is correct |
19 |
Correct |
211 ms |
97648 KB |
Output is correct |
20 |
Correct |
207 ms |
83752 KB |
Output is correct |
21 |
Correct |
259 ms |
92252 KB |
Output is correct |
22 |
Correct |
219 ms |
83852 KB |
Output is correct |
23 |
Correct |
315 ms |
92268 KB |
Output is correct |
24 |
Correct |
58 ms |
41692 KB |
Output is correct |
25 |
Correct |
67 ms |
41708 KB |
Output is correct |
26 |
Correct |
131 ms |
67408 KB |
Output is correct |
27 |
Correct |
133 ms |
61588 KB |
Output is correct |
28 |
Correct |
181 ms |
95868 KB |
Output is correct |
29 |
Correct |
246 ms |
96128 KB |
Output is correct |
30 |
Correct |
197 ms |
96300 KB |
Output is correct |
31 |
Correct |
177 ms |
96272 KB |
Output is correct |
32 |
Correct |
5 ms |
7236 KB |
Output is correct |
33 |
Correct |
5 ms |
7252 KB |
Output is correct |
34 |
Correct |
4 ms |
7300 KB |
Output is correct |
35 |
Correct |
6 ms |
7252 KB |
Output is correct |
36 |
Correct |
4 ms |
7296 KB |
Output is correct |
37 |
Correct |
5 ms |
7252 KB |
Output is correct |
38 |
Correct |
5 ms |
7252 KB |
Output is correct |
39 |
Correct |
6 ms |
7252 KB |
Output is correct |
40 |
Correct |
6 ms |
7644 KB |
Output is correct |
41 |
Correct |
9 ms |
8788 KB |
Output is correct |
42 |
Correct |
6 ms |
7764 KB |
Output is correct |
43 |
Correct |
6 ms |
8020 KB |
Output is correct |
44 |
Correct |
4 ms |
7380 KB |
Output is correct |
45 |
Correct |
5 ms |
7892 KB |
Output is correct |
46 |
Correct |
6 ms |
7508 KB |
Output is correct |
47 |
Correct |
7 ms |
8532 KB |
Output is correct |
48 |
Correct |
81 ms |
32940 KB |
Output is correct |
49 |
Correct |
89 ms |
33608 KB |
Output is correct |
50 |
Correct |
89 ms |
33376 KB |
Output is correct |
51 |
Correct |
96 ms |
33420 KB |
Output is correct |
52 |
Correct |
77 ms |
33384 KB |
Output is correct |
53 |
Correct |
157 ms |
59452 KB |
Output is correct |
54 |
Correct |
19 ms |
12504 KB |
Output is correct |
55 |
Correct |
63 ms |
24324 KB |
Output is correct |
56 |
Correct |
7 ms |
8020 KB |
Output is correct |
57 |
Correct |
23 ms |
12140 KB |
Output is correct |
58 |
Correct |
9 ms |
9928 KB |
Output is correct |
59 |
Correct |
444 ms |
133688 KB |
Output is correct |
60 |
Correct |
739 ms |
180264 KB |
Output is correct |
61 |
Correct |
486 ms |
180064 KB |
Output is correct |
62 |
Correct |
563 ms |
180144 KB |
Output is correct |
63 |
Correct |
601 ms |
182896 KB |
Output is correct |
64 |
Correct |
471 ms |
179728 KB |
Output is correct |
65 |
Correct |
469 ms |
179404 KB |
Output is correct |
66 |
Correct |
203 ms |
76036 KB |
Output is correct |
67 |
Correct |
629 ms |
182360 KB |
Output is correct |
68 |
Correct |
225 ms |
95872 KB |
Output is correct |
69 |
Correct |
175 ms |
81136 KB |
Output is correct |
70 |
Correct |
343 ms |
155160 KB |
Output is correct |
71 |
Correct |
4 ms |
7252 KB |
Output is correct |
72 |
Correct |
4 ms |
7356 KB |
Output is correct |
73 |
Correct |
4 ms |
7252 KB |
Output is correct |
74 |
Correct |
5 ms |
7252 KB |
Output is correct |
75 |
Correct |
5 ms |
7252 KB |
Output is correct |
76 |
Correct |
5 ms |
7252 KB |
Output is correct |
77 |
Correct |
57 ms |
41776 KB |
Output is correct |
78 |
Correct |
65 ms |
41668 KB |
Output is correct |
79 |
Correct |
54 ms |
41776 KB |
Output is correct |
80 |
Correct |
55 ms |
41664 KB |
Output is correct |
81 |
Correct |
265 ms |
97324 KB |
Output is correct |
82 |
Correct |
328 ms |
155196 KB |
Output is correct |
83 |
Correct |
339 ms |
156340 KB |
Output is correct |
84 |
Correct |
749 ms |
207384 KB |
Output is correct |
85 |
Correct |
757 ms |
210532 KB |
Output is correct |
86 |
Correct |
500 ms |
206704 KB |
Output is correct |
87 |
Correct |
521 ms |
211028 KB |
Output is correct |
88 |
Correct |
5 ms |
7348 KB |
Output is correct |
89 |
Correct |
533 ms |
211772 KB |
Output is correct |
90 |
Correct |
586 ms |
211884 KB |
Output is correct |
91 |
Correct |
514 ms |
212692 KB |
Output is correct |