//by szh
#include<bits/stdc++.h>
#include "fish.h"
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
const int maxn = 300010;
ll tree[2][maxn],add[2][maxn];
int y[maxn];
int xmax,ymax;
vector <pii> fish[maxn];
ll hi0[maxn],hin[maxn];
ll sum[maxn];
void push_down(int id,int c) {
if (add[id][c]==0) return;
tree[id][c<<1] = max(tree[id][c<<1],add[id][c]);
add[id][c<<1] = max(add[id][c<<1],add[id][c]);
tree[id][c<<1|1] = max(tree[id][c<<1|1],add[id][c]);
add[id][c<<1|1] = max(add[id][c<<1|1],add[id][c]);
add[id][c]=0;
}
void update(int id,int c,int cl,int cr,int l,int r,ll val) {
if (l<=cl and cr<=r) {
add[id][c] = max(add[id][c],val);
tree[id][c] = max(tree[id][c],val);
return;
}
push_down(id,c);
int mid=cl+cr>>1;
if (l<=mid) update(id,c<<1,cl,mid,l,r,val);
if (r>mid) update(id,c<<1|1,mid+1,cr,l,r,val);
tree[id][c] = max(tree[id][c<<1],tree[id][c<<1|1]);
return;
}
ll query(int id,int c,int cl,int cr,int pos) {
if (cl==cr) return tree[id][c];
push_down(id,c);
int mid=cl+cr>>1;
if (pos<=mid) return query(id,c<<1,cl,mid,pos);
else return query(id,c<<1|1,mid+1,cr,pos);
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,std::vector<int> W) {
rep(i,0,M) {
y[i] = Y[i];
y[i]++;
fish[X[i]].pb({y[i],W[i]});
sum[X[i]]+=W[i];
}
rep(i,0,N) sort(ALL(fish[i]));
rep(i,1,N) {
//increasing
for (pair<int,ll> x:fish[i-1]) {
ll tmp = query(0,1,0,N,x.fi-1);
// debug(tmp);debug(x.fi),debug(x.se);
update(0,1,0,N,x.fi,N,tmp+x.se);
}
for (int j = SZ(fish[i])-1;j>=0;j--) {
pair<int,ll> x = fish[i][j];
// if (i==70) debug(x.fi);
ll tmp = query(1,1,0,N,x.fi);
update(1,1,0,N,0,x.fi-1,tmp+x.se);
}
hi0[i] = query(1,1,0,N,0);
hin[i] = query(0,1,0,N,N);
// rep(j,0,N+1) cout<<i<<" "<<j<<" "<<query(0,1,0,N,j)<<" "<<query(1,1,0,N,j)<<endl;
update(0,1,0,N,0,N,hi0[i-1]);
if (i>=2) update(1,1,0,N,0,N,hin[i-2]+sum[i-1]);
ll tmp1 = query(1,1,0,N,N), tmp2 = query(0,1,0,N,N);
update(0,1,0,N,N,N,max(tmp1,tmp2));
update(1,1,0,N,0,N,max(tmp1,tmp2));
// rep(j,0,N+1) cout<<i<<" "<<j<<" "<<query(0,1,0,N,j)<<" "<<query(1,1,0,N,j)<<endl;
}
return max(tree[0][1],tree[1][1]);
}
Compilation message
fish.cpp: In function 'void update(int, int, int, int, int, int, long long int)':
fish.cpp:50:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
50 | int mid=cl+cr>>1;
| ~~^~~
fish.cpp: In function 'long long int query(int, int, int, int, int)':
fish.cpp:60:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
60 | int mid=cl+cr>>1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
15876 KB |
Output is correct |
2 |
Correct |
125 ms |
16732 KB |
Output is correct |
3 |
Correct |
78 ms |
8984 KB |
Output is correct |
4 |
Correct |
55 ms |
9032 KB |
Output is correct |
5 |
Correct |
334 ms |
27932 KB |
Output is correct |
6 |
Correct |
516 ms |
30580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
207 ms |
22804 KB |
Output is correct |
3 |
Correct |
277 ms |
24540 KB |
Output is correct |
4 |
Correct |
109 ms |
15936 KB |
Output is correct |
5 |
Correct |
141 ms |
16736 KB |
Output is correct |
6 |
Correct |
6 ms |
7380 KB |
Output is correct |
7 |
Correct |
5 ms |
7380 KB |
Output is correct |
8 |
Correct |
4 ms |
7380 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Correct |
60 ms |
8984 KB |
Output is correct |
11 |
Correct |
64 ms |
9076 KB |
Output is correct |
12 |
Correct |
184 ms |
19984 KB |
Output is correct |
13 |
Correct |
178 ms |
20804 KB |
Output is correct |
14 |
Correct |
124 ms |
17936 KB |
Output is correct |
15 |
Correct |
137 ms |
16560 KB |
Output is correct |
16 |
Correct |
150 ms |
18048 KB |
Output is correct |
17 |
Correct |
172 ms |
18532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
9080 KB |
Output is correct |
2 |
Correct |
46 ms |
9000 KB |
Output is correct |
3 |
Correct |
122 ms |
12688 KB |
Output is correct |
4 |
Correct |
122 ms |
12260 KB |
Output is correct |
5 |
Correct |
196 ms |
17324 KB |
Output is correct |
6 |
Correct |
165 ms |
16712 KB |
Output is correct |
7 |
Correct |
193 ms |
17228 KB |
Output is correct |
8 |
Correct |
217 ms |
17244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7380 KB |
Output is correct |
3 |
Correct |
6 ms |
7380 KB |
Output is correct |
4 |
Correct |
5 ms |
7380 KB |
Output is correct |
5 |
Correct |
6 ms |
7360 KB |
Output is correct |
6 |
Correct |
6 ms |
7336 KB |
Output is correct |
7 |
Correct |
6 ms |
7364 KB |
Output is correct |
8 |
Correct |
7 ms |
7380 KB |
Output is correct |
9 |
Correct |
6 ms |
7380 KB |
Output is correct |
10 |
Correct |
7 ms |
7504 KB |
Output is correct |
11 |
Correct |
6 ms |
7368 KB |
Output is correct |
12 |
Correct |
8 ms |
7492 KB |
Output is correct |
13 |
Correct |
6 ms |
7380 KB |
Output is correct |
14 |
Correct |
5 ms |
7376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7380 KB |
Output is correct |
3 |
Correct |
6 ms |
7380 KB |
Output is correct |
4 |
Correct |
5 ms |
7380 KB |
Output is correct |
5 |
Correct |
6 ms |
7360 KB |
Output is correct |
6 |
Correct |
6 ms |
7336 KB |
Output is correct |
7 |
Correct |
6 ms |
7364 KB |
Output is correct |
8 |
Correct |
7 ms |
7380 KB |
Output is correct |
9 |
Correct |
6 ms |
7380 KB |
Output is correct |
10 |
Correct |
7 ms |
7504 KB |
Output is correct |
11 |
Correct |
6 ms |
7368 KB |
Output is correct |
12 |
Correct |
8 ms |
7492 KB |
Output is correct |
13 |
Correct |
6 ms |
7380 KB |
Output is correct |
14 |
Correct |
5 ms |
7376 KB |
Output is correct |
15 |
Correct |
6 ms |
7412 KB |
Output is correct |
16 |
Correct |
7 ms |
7544 KB |
Output is correct |
17 |
Correct |
37 ms |
9928 KB |
Output is correct |
18 |
Correct |
39 ms |
10156 KB |
Output is correct |
19 |
Correct |
47 ms |
10048 KB |
Output is correct |
20 |
Correct |
47 ms |
10140 KB |
Output is correct |
21 |
Correct |
38 ms |
10092 KB |
Output is correct |
22 |
Correct |
65 ms |
12760 KB |
Output is correct |
23 |
Correct |
11 ms |
7896 KB |
Output is correct |
24 |
Correct |
24 ms |
9092 KB |
Output is correct |
25 |
Correct |
6 ms |
7504 KB |
Output is correct |
26 |
Correct |
11 ms |
7932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7380 KB |
Output is correct |
3 |
Correct |
6 ms |
7380 KB |
Output is correct |
4 |
Correct |
5 ms |
7380 KB |
Output is correct |
5 |
Correct |
6 ms |
7360 KB |
Output is correct |
6 |
Correct |
6 ms |
7336 KB |
Output is correct |
7 |
Correct |
6 ms |
7364 KB |
Output is correct |
8 |
Correct |
7 ms |
7380 KB |
Output is correct |
9 |
Correct |
6 ms |
7380 KB |
Output is correct |
10 |
Correct |
7 ms |
7504 KB |
Output is correct |
11 |
Correct |
6 ms |
7368 KB |
Output is correct |
12 |
Correct |
8 ms |
7492 KB |
Output is correct |
13 |
Correct |
6 ms |
7380 KB |
Output is correct |
14 |
Correct |
5 ms |
7376 KB |
Output is correct |
15 |
Correct |
6 ms |
7412 KB |
Output is correct |
16 |
Correct |
7 ms |
7544 KB |
Output is correct |
17 |
Correct |
37 ms |
9928 KB |
Output is correct |
18 |
Correct |
39 ms |
10156 KB |
Output is correct |
19 |
Correct |
47 ms |
10048 KB |
Output is correct |
20 |
Correct |
47 ms |
10140 KB |
Output is correct |
21 |
Correct |
38 ms |
10092 KB |
Output is correct |
22 |
Correct |
65 ms |
12760 KB |
Output is correct |
23 |
Correct |
11 ms |
7896 KB |
Output is correct |
24 |
Correct |
24 ms |
9092 KB |
Output is correct |
25 |
Correct |
6 ms |
7504 KB |
Output is correct |
26 |
Correct |
11 ms |
7932 KB |
Output is correct |
27 |
Correct |
13 ms |
7872 KB |
Output is correct |
28 |
Correct |
163 ms |
20400 KB |
Output is correct |
29 |
Correct |
264 ms |
25324 KB |
Output is correct |
30 |
Correct |
283 ms |
24936 KB |
Output is correct |
31 |
Correct |
265 ms |
24924 KB |
Output is correct |
32 |
Correct |
273 ms |
25696 KB |
Output is correct |
33 |
Correct |
314 ms |
24908 KB |
Output is correct |
34 |
Correct |
265 ms |
24916 KB |
Output is correct |
35 |
Correct |
108 ms |
14284 KB |
Output is correct |
36 |
Correct |
258 ms |
25580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
9080 KB |
Output is correct |
2 |
Correct |
46 ms |
9000 KB |
Output is correct |
3 |
Correct |
122 ms |
12688 KB |
Output is correct |
4 |
Correct |
122 ms |
12260 KB |
Output is correct |
5 |
Correct |
196 ms |
17324 KB |
Output is correct |
6 |
Correct |
165 ms |
16712 KB |
Output is correct |
7 |
Correct |
193 ms |
17228 KB |
Output is correct |
8 |
Correct |
217 ms |
17244 KB |
Output is correct |
9 |
Correct |
225 ms |
25144 KB |
Output is correct |
10 |
Correct |
150 ms |
14656 KB |
Output is correct |
11 |
Correct |
261 ms |
21884 KB |
Output is correct |
12 |
Correct |
5 ms |
7360 KB |
Output is correct |
13 |
Correct |
5 ms |
7360 KB |
Output is correct |
14 |
Correct |
5 ms |
7380 KB |
Output is correct |
15 |
Correct |
4 ms |
7380 KB |
Output is correct |
16 |
Correct |
10 ms |
7356 KB |
Output is correct |
17 |
Correct |
6 ms |
7380 KB |
Output is correct |
18 |
Correct |
61 ms |
9076 KB |
Output is correct |
19 |
Correct |
75 ms |
9040 KB |
Output is correct |
20 |
Correct |
53 ms |
9044 KB |
Output is correct |
21 |
Correct |
40 ms |
9072 KB |
Output is correct |
22 |
Correct |
236 ms |
24780 KB |
Output is correct |
23 |
Correct |
271 ms |
22028 KB |
Output is correct |
24 |
Correct |
343 ms |
22896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
15876 KB |
Output is correct |
2 |
Correct |
125 ms |
16732 KB |
Output is correct |
3 |
Correct |
78 ms |
8984 KB |
Output is correct |
4 |
Correct |
55 ms |
9032 KB |
Output is correct |
5 |
Correct |
334 ms |
27932 KB |
Output is correct |
6 |
Correct |
516 ms |
30580 KB |
Output is correct |
7 |
Correct |
4 ms |
7380 KB |
Output is correct |
8 |
Correct |
207 ms |
22804 KB |
Output is correct |
9 |
Correct |
277 ms |
24540 KB |
Output is correct |
10 |
Correct |
109 ms |
15936 KB |
Output is correct |
11 |
Correct |
141 ms |
16736 KB |
Output is correct |
12 |
Correct |
6 ms |
7380 KB |
Output is correct |
13 |
Correct |
5 ms |
7380 KB |
Output is correct |
14 |
Correct |
4 ms |
7380 KB |
Output is correct |
15 |
Correct |
4 ms |
7380 KB |
Output is correct |
16 |
Correct |
60 ms |
8984 KB |
Output is correct |
17 |
Correct |
64 ms |
9076 KB |
Output is correct |
18 |
Correct |
184 ms |
19984 KB |
Output is correct |
19 |
Correct |
178 ms |
20804 KB |
Output is correct |
20 |
Correct |
124 ms |
17936 KB |
Output is correct |
21 |
Correct |
137 ms |
16560 KB |
Output is correct |
22 |
Correct |
150 ms |
18048 KB |
Output is correct |
23 |
Correct |
172 ms |
18532 KB |
Output is correct |
24 |
Correct |
66 ms |
9080 KB |
Output is correct |
25 |
Correct |
46 ms |
9000 KB |
Output is correct |
26 |
Correct |
122 ms |
12688 KB |
Output is correct |
27 |
Correct |
122 ms |
12260 KB |
Output is correct |
28 |
Correct |
196 ms |
17324 KB |
Output is correct |
29 |
Correct |
165 ms |
16712 KB |
Output is correct |
30 |
Correct |
193 ms |
17228 KB |
Output is correct |
31 |
Correct |
217 ms |
17244 KB |
Output is correct |
32 |
Correct |
5 ms |
7380 KB |
Output is correct |
33 |
Correct |
5 ms |
7380 KB |
Output is correct |
34 |
Correct |
6 ms |
7380 KB |
Output is correct |
35 |
Correct |
5 ms |
7380 KB |
Output is correct |
36 |
Correct |
6 ms |
7360 KB |
Output is correct |
37 |
Correct |
6 ms |
7336 KB |
Output is correct |
38 |
Correct |
6 ms |
7364 KB |
Output is correct |
39 |
Correct |
7 ms |
7380 KB |
Output is correct |
40 |
Correct |
6 ms |
7380 KB |
Output is correct |
41 |
Correct |
7 ms |
7504 KB |
Output is correct |
42 |
Correct |
6 ms |
7368 KB |
Output is correct |
43 |
Correct |
8 ms |
7492 KB |
Output is correct |
44 |
Correct |
6 ms |
7380 KB |
Output is correct |
45 |
Correct |
5 ms |
7376 KB |
Output is correct |
46 |
Correct |
6 ms |
7412 KB |
Output is correct |
47 |
Correct |
7 ms |
7544 KB |
Output is correct |
48 |
Correct |
37 ms |
9928 KB |
Output is correct |
49 |
Correct |
39 ms |
10156 KB |
Output is correct |
50 |
Correct |
47 ms |
10048 KB |
Output is correct |
51 |
Correct |
47 ms |
10140 KB |
Output is correct |
52 |
Correct |
38 ms |
10092 KB |
Output is correct |
53 |
Correct |
65 ms |
12760 KB |
Output is correct |
54 |
Correct |
11 ms |
7896 KB |
Output is correct |
55 |
Correct |
24 ms |
9092 KB |
Output is correct |
56 |
Correct |
6 ms |
7504 KB |
Output is correct |
57 |
Correct |
11 ms |
7932 KB |
Output is correct |
58 |
Correct |
13 ms |
7872 KB |
Output is correct |
59 |
Correct |
163 ms |
20400 KB |
Output is correct |
60 |
Correct |
264 ms |
25324 KB |
Output is correct |
61 |
Correct |
283 ms |
24936 KB |
Output is correct |
62 |
Correct |
265 ms |
24924 KB |
Output is correct |
63 |
Correct |
273 ms |
25696 KB |
Output is correct |
64 |
Correct |
314 ms |
24908 KB |
Output is correct |
65 |
Correct |
265 ms |
24916 KB |
Output is correct |
66 |
Correct |
108 ms |
14284 KB |
Output is correct |
67 |
Correct |
258 ms |
25580 KB |
Output is correct |
68 |
Correct |
225 ms |
25144 KB |
Output is correct |
69 |
Correct |
150 ms |
14656 KB |
Output is correct |
70 |
Correct |
261 ms |
21884 KB |
Output is correct |
71 |
Correct |
5 ms |
7360 KB |
Output is correct |
72 |
Correct |
5 ms |
7360 KB |
Output is correct |
73 |
Correct |
5 ms |
7380 KB |
Output is correct |
74 |
Correct |
4 ms |
7380 KB |
Output is correct |
75 |
Correct |
10 ms |
7356 KB |
Output is correct |
76 |
Correct |
6 ms |
7380 KB |
Output is correct |
77 |
Correct |
61 ms |
9076 KB |
Output is correct |
78 |
Correct |
75 ms |
9040 KB |
Output is correct |
79 |
Correct |
53 ms |
9044 KB |
Output is correct |
80 |
Correct |
40 ms |
9072 KB |
Output is correct |
81 |
Correct |
236 ms |
24780 KB |
Output is correct |
82 |
Correct |
271 ms |
22028 KB |
Output is correct |
83 |
Correct |
343 ms |
22896 KB |
Output is correct |
84 |
Correct |
383 ms |
34088 KB |
Output is correct |
85 |
Correct |
377 ms |
33680 KB |
Output is correct |
86 |
Correct |
490 ms |
36960 KB |
Output is correct |
87 |
Correct |
522 ms |
37332 KB |
Output is correct |
88 |
Correct |
5 ms |
7364 KB |
Output is correct |
89 |
Correct |
564 ms |
37400 KB |
Output is correct |
90 |
Correct |
369 ms |
27396 KB |
Output is correct |
91 |
Correct |
330 ms |
26860 KB |
Output is correct |