#include<bits/stdc++.h>
#define fi first
#define se second
#define pitem item*
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=3e5+10;
const int SS=1<<17;
const int INFi=2e9;
const ll INFl=1e13;
const ll mod2=998244353;
const ll mod=1e9+7;
const ll mod3=1000696969;
const ll p=70032301;
const ull p2=913;
const int L=20;
vector<pair<int,int> > t[N];
struct tr{
ll seg[(SS<<1)+10];
void upd(int a,int b,ll x){
for(a+=SS-1,b+=SS+1;(a>>1)!=(b>>1);a>>=1,b>>=1){
if(!(a&1)) seg[a+1]=max(seg[a+1],x);
if(b&1) seg[b-1]=max(seg[b-1],x);
}
}
ll Query(int a){
ll res=0;
for(a+=SS;a>0;a>>=1) res=max(res,seg[a]);
return res;
}
};
tr dp1,dp2;
ll max_weights(int n,int m,vi x,vi y,vi w){
for(int i=1;i<=(SS<<1);i++) dp1.seg[i]=0,dp2.seg[i]=0;
for(int i=0;i<m;i++) t[x[i]+1].push_back({y[i]+1,w[i]});
for(int i=1;i<=n;i++) sort(t[i].begin(),t[i].end());
ll sum=0;
for(int i=1;i<=n;i++){
ll val=dp1.Query(n);
dp1.upd(0,0,dp2.Query(1));
int pop=0;
for(auto [u,c]:t[i]){
if(pop!=u-1) dp1.upd(pop+1,u-1,dp1.Query(pop));
dp1.upd(u,u,dp1.Query(u-1)+(ll)c);
pop=u;
sum+=(ll)c;
}
if(pop!=n) dp1.upd(pop+1,n,dp1.Query(pop));
dp1.upd(0,n,val);
pop=n+1;
reverse(t[i].begin(),t[i].end());
if(i==1) continue;
for(auto [u,c]:t[i]){
if(pop!=u+1) dp2.upd(u+1,pop-1,dp2.Query(pop));
dp2.upd(u,u,dp2.Query(u+1)+(ll)c);
pop=u;
}
if(pop!=1) dp2.upd(1,pop-1,dp2.Query(pop));
dp2.upd(1,n+1,val);
}
return dp2.Query(1);
}
/*int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
int n,m;
cin>>n>>m;
vi x,y,w;
for(int i=1;i<=m;i++){
int a,b,c;
cin>>a>>b>>c;
x.push_back(a),y.push_back(b),w.push_back(c);
}
cout<<max_weights(n,m,x,y,w)<<"\n";
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
15828 KB |
Output is correct |
2 |
Correct |
46 ms |
16852 KB |
Output is correct |
3 |
Correct |
19 ms |
11412 KB |
Output is correct |
4 |
Correct |
27 ms |
11356 KB |
Output is correct |
5 |
Correct |
114 ms |
27432 KB |
Output is correct |
6 |
Correct |
180 ms |
29636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
11356 KB |
Output is correct |
2 |
Correct |
64 ms |
19872 KB |
Output is correct |
3 |
Correct |
76 ms |
21544 KB |
Output is correct |
4 |
Correct |
40 ms |
15828 KB |
Output is correct |
5 |
Correct |
50 ms |
16668 KB |
Output is correct |
6 |
Correct |
2 ms |
11352 KB |
Output is correct |
7 |
Correct |
2 ms |
11356 KB |
Output is correct |
8 |
Correct |
4 ms |
11356 KB |
Output is correct |
9 |
Correct |
2 ms |
11356 KB |
Output is correct |
10 |
Correct |
19 ms |
11592 KB |
Output is correct |
11 |
Correct |
20 ms |
11356 KB |
Output is correct |
12 |
Correct |
46 ms |
16084 KB |
Output is correct |
13 |
Correct |
46 ms |
16848 KB |
Output is correct |
14 |
Correct |
44 ms |
15728 KB |
Output is correct |
15 |
Correct |
53 ms |
16088 KB |
Output is correct |
16 |
Correct |
41 ms |
15688 KB |
Output is correct |
17 |
Correct |
44 ms |
16088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
11352 KB |
Output is correct |
2 |
Correct |
20 ms |
11356 KB |
Output is correct |
3 |
Correct |
34 ms |
15448 KB |
Output is correct |
4 |
Correct |
29 ms |
14172 KB |
Output is correct |
5 |
Correct |
47 ms |
18676 KB |
Output is correct |
6 |
Correct |
51 ms |
18008 KB |
Output is correct |
7 |
Correct |
57 ms |
18608 KB |
Output is correct |
8 |
Correct |
51 ms |
18520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
11608 KB |
Output is correct |
2 |
Correct |
2 ms |
11356 KB |
Output is correct |
3 |
Correct |
2 ms |
11356 KB |
Output is correct |
4 |
Correct |
2 ms |
11356 KB |
Output is correct |
5 |
Correct |
2 ms |
11356 KB |
Output is correct |
6 |
Correct |
2 ms |
11352 KB |
Output is correct |
7 |
Correct |
3 ms |
11352 KB |
Output is correct |
8 |
Correct |
2 ms |
11356 KB |
Output is correct |
9 |
Correct |
2 ms |
11612 KB |
Output is correct |
10 |
Correct |
3 ms |
11612 KB |
Output is correct |
11 |
Correct |
2 ms |
11608 KB |
Output is correct |
12 |
Correct |
2 ms |
11612 KB |
Output is correct |
13 |
Correct |
2 ms |
11352 KB |
Output is correct |
14 |
Correct |
2 ms |
11864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
11608 KB |
Output is correct |
2 |
Correct |
2 ms |
11356 KB |
Output is correct |
3 |
Correct |
2 ms |
11356 KB |
Output is correct |
4 |
Correct |
2 ms |
11356 KB |
Output is correct |
5 |
Correct |
2 ms |
11356 KB |
Output is correct |
6 |
Correct |
2 ms |
11352 KB |
Output is correct |
7 |
Correct |
3 ms |
11352 KB |
Output is correct |
8 |
Correct |
2 ms |
11356 KB |
Output is correct |
9 |
Correct |
2 ms |
11612 KB |
Output is correct |
10 |
Correct |
3 ms |
11612 KB |
Output is correct |
11 |
Correct |
2 ms |
11608 KB |
Output is correct |
12 |
Correct |
2 ms |
11612 KB |
Output is correct |
13 |
Correct |
2 ms |
11352 KB |
Output is correct |
14 |
Correct |
2 ms |
11864 KB |
Output is correct |
15 |
Correct |
3 ms |
11356 KB |
Output is correct |
16 |
Correct |
3 ms |
11612 KB |
Output is correct |
17 |
Correct |
14 ms |
13916 KB |
Output is correct |
18 |
Correct |
14 ms |
14172 KB |
Output is correct |
19 |
Correct |
13 ms |
13916 KB |
Output is correct |
20 |
Correct |
13 ms |
13916 KB |
Output is correct |
21 |
Correct |
14 ms |
13968 KB |
Output is correct |
22 |
Correct |
24 ms |
16552 KB |
Output is correct |
23 |
Correct |
5 ms |
11864 KB |
Output is correct |
24 |
Correct |
11 ms |
12956 KB |
Output is correct |
25 |
Correct |
3 ms |
11608 KB |
Output is correct |
26 |
Correct |
4 ms |
11868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
11608 KB |
Output is correct |
2 |
Correct |
2 ms |
11356 KB |
Output is correct |
3 |
Correct |
2 ms |
11356 KB |
Output is correct |
4 |
Correct |
2 ms |
11356 KB |
Output is correct |
5 |
Correct |
2 ms |
11356 KB |
Output is correct |
6 |
Correct |
2 ms |
11352 KB |
Output is correct |
7 |
Correct |
3 ms |
11352 KB |
Output is correct |
8 |
Correct |
2 ms |
11356 KB |
Output is correct |
9 |
Correct |
2 ms |
11612 KB |
Output is correct |
10 |
Correct |
3 ms |
11612 KB |
Output is correct |
11 |
Correct |
2 ms |
11608 KB |
Output is correct |
12 |
Correct |
2 ms |
11612 KB |
Output is correct |
13 |
Correct |
2 ms |
11352 KB |
Output is correct |
14 |
Correct |
2 ms |
11864 KB |
Output is correct |
15 |
Correct |
3 ms |
11356 KB |
Output is correct |
16 |
Correct |
3 ms |
11612 KB |
Output is correct |
17 |
Correct |
14 ms |
13916 KB |
Output is correct |
18 |
Correct |
14 ms |
14172 KB |
Output is correct |
19 |
Correct |
13 ms |
13916 KB |
Output is correct |
20 |
Correct |
13 ms |
13916 KB |
Output is correct |
21 |
Correct |
14 ms |
13968 KB |
Output is correct |
22 |
Correct |
24 ms |
16552 KB |
Output is correct |
23 |
Correct |
5 ms |
11864 KB |
Output is correct |
24 |
Correct |
11 ms |
12956 KB |
Output is correct |
25 |
Correct |
3 ms |
11608 KB |
Output is correct |
26 |
Correct |
4 ms |
11868 KB |
Output is correct |
27 |
Correct |
4 ms |
11608 KB |
Output is correct |
28 |
Correct |
56 ms |
23668 KB |
Output is correct |
29 |
Correct |
84 ms |
27988 KB |
Output is correct |
30 |
Correct |
101 ms |
27476 KB |
Output is correct |
31 |
Correct |
103 ms |
27476 KB |
Output is correct |
32 |
Correct |
76 ms |
28504 KB |
Output is correct |
33 |
Correct |
106 ms |
27476 KB |
Output is correct |
34 |
Correct |
106 ms |
27392 KB |
Output is correct |
35 |
Correct |
36 ms |
17748 KB |
Output is correct |
36 |
Correct |
113 ms |
28244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
11352 KB |
Output is correct |
2 |
Correct |
20 ms |
11356 KB |
Output is correct |
3 |
Correct |
34 ms |
15448 KB |
Output is correct |
4 |
Correct |
29 ms |
14172 KB |
Output is correct |
5 |
Correct |
47 ms |
18676 KB |
Output is correct |
6 |
Correct |
51 ms |
18008 KB |
Output is correct |
7 |
Correct |
57 ms |
18608 KB |
Output is correct |
8 |
Correct |
51 ms |
18520 KB |
Output is correct |
9 |
Correct |
66 ms |
18344 KB |
Output is correct |
10 |
Correct |
36 ms |
16980 KB |
Output is correct |
11 |
Correct |
70 ms |
22896 KB |
Output is correct |
12 |
Correct |
2 ms |
11356 KB |
Output is correct |
13 |
Correct |
2 ms |
11356 KB |
Output is correct |
14 |
Correct |
2 ms |
11356 KB |
Output is correct |
15 |
Correct |
2 ms |
11356 KB |
Output is correct |
16 |
Correct |
2 ms |
11456 KB |
Output is correct |
17 |
Correct |
2 ms |
11356 KB |
Output is correct |
18 |
Correct |
19 ms |
11584 KB |
Output is correct |
19 |
Correct |
20 ms |
11356 KB |
Output is correct |
20 |
Correct |
20 ms |
11356 KB |
Output is correct |
21 |
Correct |
19 ms |
11352 KB |
Output is correct |
22 |
Correct |
75 ms |
18136 KB |
Output is correct |
23 |
Correct |
74 ms |
22868 KB |
Output is correct |
24 |
Correct |
95 ms |
23388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
15828 KB |
Output is correct |
2 |
Correct |
46 ms |
16852 KB |
Output is correct |
3 |
Correct |
19 ms |
11412 KB |
Output is correct |
4 |
Correct |
27 ms |
11356 KB |
Output is correct |
5 |
Correct |
114 ms |
27432 KB |
Output is correct |
6 |
Correct |
180 ms |
29636 KB |
Output is correct |
7 |
Correct |
2 ms |
11356 KB |
Output is correct |
8 |
Correct |
64 ms |
19872 KB |
Output is correct |
9 |
Correct |
76 ms |
21544 KB |
Output is correct |
10 |
Correct |
40 ms |
15828 KB |
Output is correct |
11 |
Correct |
50 ms |
16668 KB |
Output is correct |
12 |
Correct |
2 ms |
11352 KB |
Output is correct |
13 |
Correct |
2 ms |
11356 KB |
Output is correct |
14 |
Correct |
4 ms |
11356 KB |
Output is correct |
15 |
Correct |
2 ms |
11356 KB |
Output is correct |
16 |
Correct |
19 ms |
11592 KB |
Output is correct |
17 |
Correct |
20 ms |
11356 KB |
Output is correct |
18 |
Correct |
46 ms |
16084 KB |
Output is correct |
19 |
Correct |
46 ms |
16848 KB |
Output is correct |
20 |
Correct |
44 ms |
15728 KB |
Output is correct |
21 |
Correct |
53 ms |
16088 KB |
Output is correct |
22 |
Correct |
41 ms |
15688 KB |
Output is correct |
23 |
Correct |
44 ms |
16088 KB |
Output is correct |
24 |
Correct |
20 ms |
11352 KB |
Output is correct |
25 |
Correct |
20 ms |
11356 KB |
Output is correct |
26 |
Correct |
34 ms |
15448 KB |
Output is correct |
27 |
Correct |
29 ms |
14172 KB |
Output is correct |
28 |
Correct |
47 ms |
18676 KB |
Output is correct |
29 |
Correct |
51 ms |
18008 KB |
Output is correct |
30 |
Correct |
57 ms |
18608 KB |
Output is correct |
31 |
Correct |
51 ms |
18520 KB |
Output is correct |
32 |
Correct |
2 ms |
11608 KB |
Output is correct |
33 |
Correct |
2 ms |
11356 KB |
Output is correct |
34 |
Correct |
2 ms |
11356 KB |
Output is correct |
35 |
Correct |
2 ms |
11356 KB |
Output is correct |
36 |
Correct |
2 ms |
11356 KB |
Output is correct |
37 |
Correct |
2 ms |
11352 KB |
Output is correct |
38 |
Correct |
3 ms |
11352 KB |
Output is correct |
39 |
Correct |
2 ms |
11356 KB |
Output is correct |
40 |
Correct |
2 ms |
11612 KB |
Output is correct |
41 |
Correct |
3 ms |
11612 KB |
Output is correct |
42 |
Correct |
2 ms |
11608 KB |
Output is correct |
43 |
Correct |
2 ms |
11612 KB |
Output is correct |
44 |
Correct |
2 ms |
11352 KB |
Output is correct |
45 |
Correct |
2 ms |
11864 KB |
Output is correct |
46 |
Correct |
3 ms |
11356 KB |
Output is correct |
47 |
Correct |
3 ms |
11612 KB |
Output is correct |
48 |
Correct |
14 ms |
13916 KB |
Output is correct |
49 |
Correct |
14 ms |
14172 KB |
Output is correct |
50 |
Correct |
13 ms |
13916 KB |
Output is correct |
51 |
Correct |
13 ms |
13916 KB |
Output is correct |
52 |
Correct |
14 ms |
13968 KB |
Output is correct |
53 |
Correct |
24 ms |
16552 KB |
Output is correct |
54 |
Correct |
5 ms |
11864 KB |
Output is correct |
55 |
Correct |
11 ms |
12956 KB |
Output is correct |
56 |
Correct |
3 ms |
11608 KB |
Output is correct |
57 |
Correct |
4 ms |
11868 KB |
Output is correct |
58 |
Correct |
4 ms |
11608 KB |
Output is correct |
59 |
Correct |
56 ms |
23668 KB |
Output is correct |
60 |
Correct |
84 ms |
27988 KB |
Output is correct |
61 |
Correct |
101 ms |
27476 KB |
Output is correct |
62 |
Correct |
103 ms |
27476 KB |
Output is correct |
63 |
Correct |
76 ms |
28504 KB |
Output is correct |
64 |
Correct |
106 ms |
27476 KB |
Output is correct |
65 |
Correct |
106 ms |
27392 KB |
Output is correct |
66 |
Correct |
36 ms |
17748 KB |
Output is correct |
67 |
Correct |
113 ms |
28244 KB |
Output is correct |
68 |
Correct |
66 ms |
18344 KB |
Output is correct |
69 |
Correct |
36 ms |
16980 KB |
Output is correct |
70 |
Correct |
70 ms |
22896 KB |
Output is correct |
71 |
Correct |
2 ms |
11356 KB |
Output is correct |
72 |
Correct |
2 ms |
11356 KB |
Output is correct |
73 |
Correct |
2 ms |
11356 KB |
Output is correct |
74 |
Correct |
2 ms |
11356 KB |
Output is correct |
75 |
Correct |
2 ms |
11456 KB |
Output is correct |
76 |
Correct |
2 ms |
11356 KB |
Output is correct |
77 |
Correct |
19 ms |
11584 KB |
Output is correct |
78 |
Correct |
20 ms |
11356 KB |
Output is correct |
79 |
Correct |
20 ms |
11356 KB |
Output is correct |
80 |
Correct |
19 ms |
11352 KB |
Output is correct |
81 |
Correct |
75 ms |
18136 KB |
Output is correct |
82 |
Correct |
74 ms |
22868 KB |
Output is correct |
83 |
Correct |
95 ms |
23388 KB |
Output is correct |
84 |
Correct |
117 ms |
27564 KB |
Output is correct |
85 |
Correct |
114 ms |
26736 KB |
Output is correct |
86 |
Correct |
179 ms |
29620 KB |
Output is correct |
87 |
Correct |
185 ms |
29792 KB |
Output is correct |
88 |
Correct |
2 ms |
11352 KB |
Output is correct |
89 |
Correct |
181 ms |
29780 KB |
Output is correct |
90 |
Correct |
110 ms |
28244 KB |
Output is correct |
91 |
Correct |
99 ms |
27728 KB |
Output is correct |