#include "fish.h"
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)
#define dforn(i, n) for(int i=(int)n-1; i>=0; --i)
#define dforsn(i, s, n) for(int i=(int)n-1; i>=s; --i)
#define PB push_back
#define F first
#define S second
int n, m;
vector<pii> pts[300010];
ll bd[100010], bu[100010];
void update(int r, ll value, ll* bit){
for(; r<n+1; r=r|(r+1)) bit[r]=max(bit[r], value);
}
ll query(int r, ll* bit, ll base=0){
ll ret = base;
for(; r>=0; r=(r&(r+1))-1) ret=max(ret, bit[r]);
return ret;
}
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
n=N, m=M;
forn(i, m) pts[X[i]].PB({Y[i], W[i]});
forn(i, n) sort(pts[i].begin(), pts[i].end());
forn(i, n+1) bd[i]=-1000000000000000000;
ll mx=0;
forn(i, n){
mx = max(mx, query(n, bu));
ll emp = max(query(n, bd), query(n, bu));
for(pii el:pts[i]){
ll a = query(el.F - 1, bu), b = query(n, bd, -1000000000000000000);
update(el.F, max(a, b) + el.S, bu);
}
dforn(ind, pts[i].size()){
pii el = pts[i][ind];
ll a = query(n - el.F - 1, bd, -1000000000000000000);
update(n - el.F, a + el.S, bd);
}
update(0, emp, bd);
}
return max(mx, query(n, bd));
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
11364 KB |
Output is correct |
2 |
Correct |
43 ms |
12104 KB |
Output is correct |
3 |
Correct |
8 ms |
8168 KB |
Output is correct |
4 |
Correct |
9 ms |
8020 KB |
Output is correct |
5 |
Correct |
115 ms |
18656 KB |
Output is correct |
6 |
Correct |
120 ms |
20224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7252 KB |
Output is correct |
2 |
Correct |
64 ms |
13896 KB |
Output is correct |
3 |
Correct |
76 ms |
15292 KB |
Output is correct |
4 |
Correct |
36 ms |
11364 KB |
Output is correct |
5 |
Correct |
42 ms |
12172 KB |
Output is correct |
6 |
Correct |
3 ms |
7268 KB |
Output is correct |
7 |
Correct |
3 ms |
7252 KB |
Output is correct |
8 |
Correct |
3 ms |
7252 KB |
Output is correct |
9 |
Correct |
3 ms |
7252 KB |
Output is correct |
10 |
Correct |
9 ms |
8164 KB |
Output is correct |
11 |
Correct |
8 ms |
8020 KB |
Output is correct |
12 |
Correct |
36 ms |
11464 KB |
Output is correct |
13 |
Correct |
42 ms |
12108 KB |
Output is correct |
14 |
Correct |
36 ms |
11456 KB |
Output is correct |
15 |
Correct |
39 ms |
11564 KB |
Output is correct |
16 |
Correct |
36 ms |
11512 KB |
Output is correct |
17 |
Correct |
39 ms |
11848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8148 KB |
Output is correct |
2 |
Correct |
8 ms |
8132 KB |
Output is correct |
3 |
Correct |
27 ms |
10940 KB |
Output is correct |
4 |
Correct |
21 ms |
10744 KB |
Output is correct |
5 |
Correct |
44 ms |
15288 KB |
Output is correct |
6 |
Correct |
37 ms |
14548 KB |
Output is correct |
7 |
Correct |
43 ms |
15180 KB |
Output is correct |
8 |
Correct |
42 ms |
15104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7252 KB |
Output is correct |
2 |
Correct |
3 ms |
7252 KB |
Output is correct |
3 |
Correct |
3 ms |
7252 KB |
Output is correct |
4 |
Correct |
3 ms |
7252 KB |
Output is correct |
5 |
Correct |
3 ms |
7252 KB |
Output is correct |
6 |
Correct |
3 ms |
7252 KB |
Output is correct |
7 |
Correct |
3 ms |
7352 KB |
Output is correct |
8 |
Correct |
3 ms |
7356 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Correct |
4 ms |
7380 KB |
Output is correct |
11 |
Correct |
4 ms |
7360 KB |
Output is correct |
12 |
Correct |
4 ms |
7388 KB |
Output is correct |
13 |
Correct |
4 ms |
7360 KB |
Output is correct |
14 |
Correct |
4 ms |
7380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7252 KB |
Output is correct |
2 |
Correct |
3 ms |
7252 KB |
Output is correct |
3 |
Correct |
3 ms |
7252 KB |
Output is correct |
4 |
Correct |
3 ms |
7252 KB |
Output is correct |
5 |
Correct |
3 ms |
7252 KB |
Output is correct |
6 |
Correct |
3 ms |
7252 KB |
Output is correct |
7 |
Correct |
3 ms |
7352 KB |
Output is correct |
8 |
Correct |
3 ms |
7356 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Correct |
4 ms |
7380 KB |
Output is correct |
11 |
Correct |
4 ms |
7360 KB |
Output is correct |
12 |
Correct |
4 ms |
7388 KB |
Output is correct |
13 |
Correct |
4 ms |
7360 KB |
Output is correct |
14 |
Correct |
4 ms |
7380 KB |
Output is correct |
15 |
Correct |
4 ms |
7380 KB |
Output is correct |
16 |
Correct |
4 ms |
7380 KB |
Output is correct |
17 |
Correct |
17 ms |
9684 KB |
Output is correct |
18 |
Correct |
16 ms |
9940 KB |
Output is correct |
19 |
Correct |
18 ms |
9792 KB |
Output is correct |
20 |
Correct |
16 ms |
9800 KB |
Output is correct |
21 |
Correct |
16 ms |
9780 KB |
Output is correct |
22 |
Correct |
30 ms |
12368 KB |
Output is correct |
23 |
Correct |
6 ms |
7764 KB |
Output is correct |
24 |
Correct |
17 ms |
8976 KB |
Output is correct |
25 |
Correct |
4 ms |
7380 KB |
Output is correct |
26 |
Correct |
7 ms |
7820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7252 KB |
Output is correct |
2 |
Correct |
3 ms |
7252 KB |
Output is correct |
3 |
Correct |
3 ms |
7252 KB |
Output is correct |
4 |
Correct |
3 ms |
7252 KB |
Output is correct |
5 |
Correct |
3 ms |
7252 KB |
Output is correct |
6 |
Correct |
3 ms |
7252 KB |
Output is correct |
7 |
Correct |
3 ms |
7352 KB |
Output is correct |
8 |
Correct |
3 ms |
7356 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Correct |
4 ms |
7380 KB |
Output is correct |
11 |
Correct |
4 ms |
7360 KB |
Output is correct |
12 |
Correct |
4 ms |
7388 KB |
Output is correct |
13 |
Correct |
4 ms |
7360 KB |
Output is correct |
14 |
Correct |
4 ms |
7380 KB |
Output is correct |
15 |
Correct |
4 ms |
7380 KB |
Output is correct |
16 |
Correct |
4 ms |
7380 KB |
Output is correct |
17 |
Correct |
17 ms |
9684 KB |
Output is correct |
18 |
Correct |
16 ms |
9940 KB |
Output is correct |
19 |
Correct |
18 ms |
9792 KB |
Output is correct |
20 |
Correct |
16 ms |
9800 KB |
Output is correct |
21 |
Correct |
16 ms |
9780 KB |
Output is correct |
22 |
Correct |
30 ms |
12368 KB |
Output is correct |
23 |
Correct |
6 ms |
7764 KB |
Output is correct |
24 |
Correct |
17 ms |
8976 KB |
Output is correct |
25 |
Correct |
4 ms |
7380 KB |
Output is correct |
26 |
Correct |
7 ms |
7820 KB |
Output is correct |
27 |
Correct |
4 ms |
7508 KB |
Output is correct |
28 |
Correct |
69 ms |
19348 KB |
Output is correct |
29 |
Correct |
99 ms |
23772 KB |
Output is correct |
30 |
Correct |
104 ms |
23360 KB |
Output is correct |
31 |
Correct |
102 ms |
23404 KB |
Output is correct |
32 |
Correct |
92 ms |
24404 KB |
Output is correct |
33 |
Correct |
99 ms |
23444 KB |
Output is correct |
34 |
Correct |
100 ms |
23396 KB |
Output is correct |
35 |
Correct |
40 ms |
13692 KB |
Output is correct |
36 |
Correct |
97 ms |
24268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8148 KB |
Output is correct |
2 |
Correct |
8 ms |
8132 KB |
Output is correct |
3 |
Correct |
27 ms |
10940 KB |
Output is correct |
4 |
Correct |
21 ms |
10744 KB |
Output is correct |
5 |
Correct |
44 ms |
15288 KB |
Output is correct |
6 |
Correct |
37 ms |
14548 KB |
Output is correct |
7 |
Correct |
43 ms |
15180 KB |
Output is correct |
8 |
Correct |
42 ms |
15104 KB |
Output is correct |
9 |
Correct |
42 ms |
15720 KB |
Output is correct |
10 |
Correct |
38 ms |
13384 KB |
Output is correct |
11 |
Correct |
73 ms |
19404 KB |
Output is correct |
12 |
Correct |
3 ms |
7252 KB |
Output is correct |
13 |
Correct |
3 ms |
7252 KB |
Output is correct |
14 |
Correct |
3 ms |
7252 KB |
Output is correct |
15 |
Correct |
4 ms |
7252 KB |
Output is correct |
16 |
Correct |
4 ms |
7252 KB |
Output is correct |
17 |
Correct |
3 ms |
7252 KB |
Output is correct |
18 |
Correct |
8 ms |
8168 KB |
Output is correct |
19 |
Correct |
8 ms |
8020 KB |
Output is correct |
20 |
Correct |
8 ms |
8148 KB |
Output is correct |
21 |
Correct |
9 ms |
8020 KB |
Output is correct |
22 |
Correct |
51 ms |
15424 KB |
Output is correct |
23 |
Correct |
72 ms |
19424 KB |
Output is correct |
24 |
Correct |
78 ms |
19924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
11364 KB |
Output is correct |
2 |
Correct |
43 ms |
12104 KB |
Output is correct |
3 |
Correct |
8 ms |
8168 KB |
Output is correct |
4 |
Correct |
9 ms |
8020 KB |
Output is correct |
5 |
Correct |
115 ms |
18656 KB |
Output is correct |
6 |
Correct |
120 ms |
20224 KB |
Output is correct |
7 |
Correct |
3 ms |
7252 KB |
Output is correct |
8 |
Correct |
64 ms |
13896 KB |
Output is correct |
9 |
Correct |
76 ms |
15292 KB |
Output is correct |
10 |
Correct |
36 ms |
11364 KB |
Output is correct |
11 |
Correct |
42 ms |
12172 KB |
Output is correct |
12 |
Correct |
3 ms |
7268 KB |
Output is correct |
13 |
Correct |
3 ms |
7252 KB |
Output is correct |
14 |
Correct |
3 ms |
7252 KB |
Output is correct |
15 |
Correct |
3 ms |
7252 KB |
Output is correct |
16 |
Correct |
9 ms |
8164 KB |
Output is correct |
17 |
Correct |
8 ms |
8020 KB |
Output is correct |
18 |
Correct |
36 ms |
11464 KB |
Output is correct |
19 |
Correct |
42 ms |
12108 KB |
Output is correct |
20 |
Correct |
36 ms |
11456 KB |
Output is correct |
21 |
Correct |
39 ms |
11564 KB |
Output is correct |
22 |
Correct |
36 ms |
11512 KB |
Output is correct |
23 |
Correct |
39 ms |
11848 KB |
Output is correct |
24 |
Correct |
8 ms |
8148 KB |
Output is correct |
25 |
Correct |
8 ms |
8132 KB |
Output is correct |
26 |
Correct |
27 ms |
10940 KB |
Output is correct |
27 |
Correct |
21 ms |
10744 KB |
Output is correct |
28 |
Correct |
44 ms |
15288 KB |
Output is correct |
29 |
Correct |
37 ms |
14548 KB |
Output is correct |
30 |
Correct |
43 ms |
15180 KB |
Output is correct |
31 |
Correct |
42 ms |
15104 KB |
Output is correct |
32 |
Correct |
3 ms |
7252 KB |
Output is correct |
33 |
Correct |
3 ms |
7252 KB |
Output is correct |
34 |
Correct |
3 ms |
7252 KB |
Output is correct |
35 |
Correct |
3 ms |
7252 KB |
Output is correct |
36 |
Correct |
3 ms |
7252 KB |
Output is correct |
37 |
Correct |
3 ms |
7252 KB |
Output is correct |
38 |
Correct |
3 ms |
7352 KB |
Output is correct |
39 |
Correct |
3 ms |
7356 KB |
Output is correct |
40 |
Correct |
4 ms |
7380 KB |
Output is correct |
41 |
Correct |
4 ms |
7380 KB |
Output is correct |
42 |
Correct |
4 ms |
7360 KB |
Output is correct |
43 |
Correct |
4 ms |
7388 KB |
Output is correct |
44 |
Correct |
4 ms |
7360 KB |
Output is correct |
45 |
Correct |
4 ms |
7380 KB |
Output is correct |
46 |
Correct |
4 ms |
7380 KB |
Output is correct |
47 |
Correct |
4 ms |
7380 KB |
Output is correct |
48 |
Correct |
17 ms |
9684 KB |
Output is correct |
49 |
Correct |
16 ms |
9940 KB |
Output is correct |
50 |
Correct |
18 ms |
9792 KB |
Output is correct |
51 |
Correct |
16 ms |
9800 KB |
Output is correct |
52 |
Correct |
16 ms |
9780 KB |
Output is correct |
53 |
Correct |
30 ms |
12368 KB |
Output is correct |
54 |
Correct |
6 ms |
7764 KB |
Output is correct |
55 |
Correct |
17 ms |
8976 KB |
Output is correct |
56 |
Correct |
4 ms |
7380 KB |
Output is correct |
57 |
Correct |
7 ms |
7820 KB |
Output is correct |
58 |
Correct |
4 ms |
7508 KB |
Output is correct |
59 |
Correct |
69 ms |
19348 KB |
Output is correct |
60 |
Correct |
99 ms |
23772 KB |
Output is correct |
61 |
Correct |
104 ms |
23360 KB |
Output is correct |
62 |
Correct |
102 ms |
23404 KB |
Output is correct |
63 |
Correct |
92 ms |
24404 KB |
Output is correct |
64 |
Correct |
99 ms |
23444 KB |
Output is correct |
65 |
Correct |
100 ms |
23396 KB |
Output is correct |
66 |
Correct |
40 ms |
13692 KB |
Output is correct |
67 |
Correct |
97 ms |
24268 KB |
Output is correct |
68 |
Correct |
42 ms |
15720 KB |
Output is correct |
69 |
Correct |
38 ms |
13384 KB |
Output is correct |
70 |
Correct |
73 ms |
19404 KB |
Output is correct |
71 |
Correct |
3 ms |
7252 KB |
Output is correct |
72 |
Correct |
3 ms |
7252 KB |
Output is correct |
73 |
Correct |
3 ms |
7252 KB |
Output is correct |
74 |
Correct |
4 ms |
7252 KB |
Output is correct |
75 |
Correct |
4 ms |
7252 KB |
Output is correct |
76 |
Correct |
3 ms |
7252 KB |
Output is correct |
77 |
Correct |
8 ms |
8168 KB |
Output is correct |
78 |
Correct |
8 ms |
8020 KB |
Output is correct |
79 |
Correct |
8 ms |
8148 KB |
Output is correct |
80 |
Correct |
9 ms |
8020 KB |
Output is correct |
81 |
Correct |
51 ms |
15424 KB |
Output is correct |
82 |
Correct |
72 ms |
19424 KB |
Output is correct |
83 |
Correct |
78 ms |
19924 KB |
Output is correct |
84 |
Correct |
118 ms |
24784 KB |
Output is correct |
85 |
Correct |
112 ms |
24256 KB |
Output is correct |
86 |
Correct |
128 ms |
26980 KB |
Output is correct |
87 |
Correct |
120 ms |
27228 KB |
Output is correct |
88 |
Correct |
3 ms |
7252 KB |
Output is correct |
89 |
Correct |
120 ms |
27120 KB |
Output is correct |
90 |
Correct |
108 ms |
24932 KB |
Output is correct |
91 |
Correct |
106 ms |
24544 KB |
Output is correct |