#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 |
57 ms |
14440 KB |
Output is correct |
2 |
Correct |
68 ms |
14912 KB |
Output is correct |
3 |
Correct |
31 ms |
11340 KB |
Output is correct |
4 |
Correct |
29 ms |
11416 KB |
Output is correct |
5 |
Correct |
150 ms |
21040 KB |
Output is correct |
6 |
Correct |
255 ms |
22860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
11348 KB |
Output is correct |
2 |
Correct |
91 ms |
16848 KB |
Output is correct |
3 |
Correct |
106 ms |
17976 KB |
Output is correct |
4 |
Correct |
56 ms |
14412 KB |
Output is correct |
5 |
Correct |
69 ms |
14912 KB |
Output is correct |
6 |
Correct |
6 ms |
11348 KB |
Output is correct |
7 |
Correct |
5 ms |
11348 KB |
Output is correct |
8 |
Correct |
5 ms |
11348 KB |
Output is correct |
9 |
Correct |
5 ms |
11348 KB |
Output is correct |
10 |
Correct |
29 ms |
11448 KB |
Output is correct |
11 |
Correct |
28 ms |
11348 KB |
Output is correct |
12 |
Correct |
60 ms |
14448 KB |
Output is correct |
13 |
Correct |
68 ms |
14840 KB |
Output is correct |
14 |
Correct |
59 ms |
14184 KB |
Output is correct |
15 |
Correct |
66 ms |
14560 KB |
Output is correct |
16 |
Correct |
59 ms |
14332 KB |
Output is correct |
17 |
Correct |
65 ms |
14548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
11448 KB |
Output is correct |
2 |
Correct |
30 ms |
11448 KB |
Output is correct |
3 |
Correct |
49 ms |
14400 KB |
Output is correct |
4 |
Correct |
44 ms |
13460 KB |
Output is correct |
5 |
Correct |
70 ms |
16844 KB |
Output is correct |
6 |
Correct |
76 ms |
16860 KB |
Output is correct |
7 |
Correct |
66 ms |
16852 KB |
Output is correct |
8 |
Correct |
66 ms |
16852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
11348 KB |
Output is correct |
2 |
Correct |
6 ms |
11348 KB |
Output is correct |
3 |
Correct |
7 ms |
11348 KB |
Output is correct |
4 |
Correct |
6 ms |
11348 KB |
Output is correct |
5 |
Correct |
6 ms |
11348 KB |
Output is correct |
6 |
Correct |
6 ms |
11348 KB |
Output is correct |
7 |
Correct |
6 ms |
11348 KB |
Output is correct |
8 |
Correct |
6 ms |
11448 KB |
Output is correct |
9 |
Correct |
6 ms |
11376 KB |
Output is correct |
10 |
Correct |
6 ms |
11476 KB |
Output is correct |
11 |
Correct |
7 ms |
11476 KB |
Output is correct |
12 |
Correct |
7 ms |
11476 KB |
Output is correct |
13 |
Correct |
6 ms |
11348 KB |
Output is correct |
14 |
Correct |
6 ms |
11376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
11348 KB |
Output is correct |
2 |
Correct |
6 ms |
11348 KB |
Output is correct |
3 |
Correct |
7 ms |
11348 KB |
Output is correct |
4 |
Correct |
6 ms |
11348 KB |
Output is correct |
5 |
Correct |
6 ms |
11348 KB |
Output is correct |
6 |
Correct |
6 ms |
11348 KB |
Output is correct |
7 |
Correct |
6 ms |
11348 KB |
Output is correct |
8 |
Correct |
6 ms |
11448 KB |
Output is correct |
9 |
Correct |
6 ms |
11376 KB |
Output is correct |
10 |
Correct |
6 ms |
11476 KB |
Output is correct |
11 |
Correct |
7 ms |
11476 KB |
Output is correct |
12 |
Correct |
7 ms |
11476 KB |
Output is correct |
13 |
Correct |
6 ms |
11348 KB |
Output is correct |
14 |
Correct |
6 ms |
11376 KB |
Output is correct |
15 |
Correct |
6 ms |
11348 KB |
Output is correct |
16 |
Correct |
7 ms |
11532 KB |
Output is correct |
17 |
Correct |
23 ms |
13012 KB |
Output is correct |
18 |
Correct |
22 ms |
13260 KB |
Output is correct |
19 |
Correct |
23 ms |
13140 KB |
Output is correct |
20 |
Correct |
22 ms |
13140 KB |
Output is correct |
21 |
Correct |
22 ms |
13136 KB |
Output is correct |
22 |
Correct |
37 ms |
14836 KB |
Output is correct |
23 |
Correct |
10 ms |
11724 KB |
Output is correct |
24 |
Correct |
20 ms |
12508 KB |
Output is correct |
25 |
Correct |
6 ms |
11480 KB |
Output is correct |
26 |
Correct |
9 ms |
11776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
11348 KB |
Output is correct |
2 |
Correct |
6 ms |
11348 KB |
Output is correct |
3 |
Correct |
7 ms |
11348 KB |
Output is correct |
4 |
Correct |
6 ms |
11348 KB |
Output is correct |
5 |
Correct |
6 ms |
11348 KB |
Output is correct |
6 |
Correct |
6 ms |
11348 KB |
Output is correct |
7 |
Correct |
6 ms |
11348 KB |
Output is correct |
8 |
Correct |
6 ms |
11448 KB |
Output is correct |
9 |
Correct |
6 ms |
11376 KB |
Output is correct |
10 |
Correct |
6 ms |
11476 KB |
Output is correct |
11 |
Correct |
7 ms |
11476 KB |
Output is correct |
12 |
Correct |
7 ms |
11476 KB |
Output is correct |
13 |
Correct |
6 ms |
11348 KB |
Output is correct |
14 |
Correct |
6 ms |
11376 KB |
Output is correct |
15 |
Correct |
6 ms |
11348 KB |
Output is correct |
16 |
Correct |
7 ms |
11532 KB |
Output is correct |
17 |
Correct |
23 ms |
13012 KB |
Output is correct |
18 |
Correct |
22 ms |
13260 KB |
Output is correct |
19 |
Correct |
23 ms |
13140 KB |
Output is correct |
20 |
Correct |
22 ms |
13140 KB |
Output is correct |
21 |
Correct |
22 ms |
13136 KB |
Output is correct |
22 |
Correct |
37 ms |
14836 KB |
Output is correct |
23 |
Correct |
10 ms |
11724 KB |
Output is correct |
24 |
Correct |
20 ms |
12508 KB |
Output is correct |
25 |
Correct |
6 ms |
11480 KB |
Output is correct |
26 |
Correct |
9 ms |
11776 KB |
Output is correct |
27 |
Correct |
8 ms |
11532 KB |
Output is correct |
28 |
Correct |
83 ms |
19724 KB |
Output is correct |
29 |
Correct |
120 ms |
22348 KB |
Output is correct |
30 |
Correct |
144 ms |
21872 KB |
Output is correct |
31 |
Correct |
146 ms |
21884 KB |
Output is correct |
32 |
Correct |
108 ms |
23280 KB |
Output is correct |
33 |
Correct |
149 ms |
22000 KB |
Output is correct |
34 |
Correct |
148 ms |
21868 KB |
Output is correct |
35 |
Correct |
52 ms |
15644 KB |
Output is correct |
36 |
Correct |
132 ms |
22732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
11448 KB |
Output is correct |
2 |
Correct |
30 ms |
11448 KB |
Output is correct |
3 |
Correct |
49 ms |
14400 KB |
Output is correct |
4 |
Correct |
44 ms |
13460 KB |
Output is correct |
5 |
Correct |
70 ms |
16844 KB |
Output is correct |
6 |
Correct |
76 ms |
16860 KB |
Output is correct |
7 |
Correct |
66 ms |
16852 KB |
Output is correct |
8 |
Correct |
66 ms |
16852 KB |
Output is correct |
9 |
Correct |
87 ms |
16840 KB |
Output is correct |
10 |
Correct |
56 ms |
15296 KB |
Output is correct |
11 |
Correct |
105 ms |
19188 KB |
Output is correct |
12 |
Correct |
6 ms |
11348 KB |
Output is correct |
13 |
Correct |
6 ms |
11348 KB |
Output is correct |
14 |
Correct |
6 ms |
11412 KB |
Output is correct |
15 |
Correct |
5 ms |
11348 KB |
Output is correct |
16 |
Correct |
5 ms |
11432 KB |
Output is correct |
17 |
Correct |
6 ms |
11344 KB |
Output is correct |
18 |
Correct |
30 ms |
11348 KB |
Output is correct |
19 |
Correct |
30 ms |
11348 KB |
Output is correct |
20 |
Correct |
29 ms |
11348 KB |
Output is correct |
21 |
Correct |
36 ms |
11424 KB |
Output is correct |
22 |
Correct |
109 ms |
15876 KB |
Output is correct |
23 |
Correct |
118 ms |
19300 KB |
Output is correct |
24 |
Correct |
123 ms |
19276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
14440 KB |
Output is correct |
2 |
Correct |
68 ms |
14912 KB |
Output is correct |
3 |
Correct |
31 ms |
11340 KB |
Output is correct |
4 |
Correct |
29 ms |
11416 KB |
Output is correct |
5 |
Correct |
150 ms |
21040 KB |
Output is correct |
6 |
Correct |
255 ms |
22860 KB |
Output is correct |
7 |
Correct |
5 ms |
11348 KB |
Output is correct |
8 |
Correct |
91 ms |
16848 KB |
Output is correct |
9 |
Correct |
106 ms |
17976 KB |
Output is correct |
10 |
Correct |
56 ms |
14412 KB |
Output is correct |
11 |
Correct |
69 ms |
14912 KB |
Output is correct |
12 |
Correct |
6 ms |
11348 KB |
Output is correct |
13 |
Correct |
5 ms |
11348 KB |
Output is correct |
14 |
Correct |
5 ms |
11348 KB |
Output is correct |
15 |
Correct |
5 ms |
11348 KB |
Output is correct |
16 |
Correct |
29 ms |
11448 KB |
Output is correct |
17 |
Correct |
28 ms |
11348 KB |
Output is correct |
18 |
Correct |
60 ms |
14448 KB |
Output is correct |
19 |
Correct |
68 ms |
14840 KB |
Output is correct |
20 |
Correct |
59 ms |
14184 KB |
Output is correct |
21 |
Correct |
66 ms |
14560 KB |
Output is correct |
22 |
Correct |
59 ms |
14332 KB |
Output is correct |
23 |
Correct |
65 ms |
14548 KB |
Output is correct |
24 |
Correct |
29 ms |
11448 KB |
Output is correct |
25 |
Correct |
30 ms |
11448 KB |
Output is correct |
26 |
Correct |
49 ms |
14400 KB |
Output is correct |
27 |
Correct |
44 ms |
13460 KB |
Output is correct |
28 |
Correct |
70 ms |
16844 KB |
Output is correct |
29 |
Correct |
76 ms |
16860 KB |
Output is correct |
30 |
Correct |
66 ms |
16852 KB |
Output is correct |
31 |
Correct |
66 ms |
16852 KB |
Output is correct |
32 |
Correct |
7 ms |
11348 KB |
Output is correct |
33 |
Correct |
6 ms |
11348 KB |
Output is correct |
34 |
Correct |
7 ms |
11348 KB |
Output is correct |
35 |
Correct |
6 ms |
11348 KB |
Output is correct |
36 |
Correct |
6 ms |
11348 KB |
Output is correct |
37 |
Correct |
6 ms |
11348 KB |
Output is correct |
38 |
Correct |
6 ms |
11348 KB |
Output is correct |
39 |
Correct |
6 ms |
11448 KB |
Output is correct |
40 |
Correct |
6 ms |
11376 KB |
Output is correct |
41 |
Correct |
6 ms |
11476 KB |
Output is correct |
42 |
Correct |
7 ms |
11476 KB |
Output is correct |
43 |
Correct |
7 ms |
11476 KB |
Output is correct |
44 |
Correct |
6 ms |
11348 KB |
Output is correct |
45 |
Correct |
6 ms |
11376 KB |
Output is correct |
46 |
Correct |
6 ms |
11348 KB |
Output is correct |
47 |
Correct |
7 ms |
11532 KB |
Output is correct |
48 |
Correct |
23 ms |
13012 KB |
Output is correct |
49 |
Correct |
22 ms |
13260 KB |
Output is correct |
50 |
Correct |
23 ms |
13140 KB |
Output is correct |
51 |
Correct |
22 ms |
13140 KB |
Output is correct |
52 |
Correct |
22 ms |
13136 KB |
Output is correct |
53 |
Correct |
37 ms |
14836 KB |
Output is correct |
54 |
Correct |
10 ms |
11724 KB |
Output is correct |
55 |
Correct |
20 ms |
12508 KB |
Output is correct |
56 |
Correct |
6 ms |
11480 KB |
Output is correct |
57 |
Correct |
9 ms |
11776 KB |
Output is correct |
58 |
Correct |
8 ms |
11532 KB |
Output is correct |
59 |
Correct |
83 ms |
19724 KB |
Output is correct |
60 |
Correct |
120 ms |
22348 KB |
Output is correct |
61 |
Correct |
144 ms |
21872 KB |
Output is correct |
62 |
Correct |
146 ms |
21884 KB |
Output is correct |
63 |
Correct |
108 ms |
23280 KB |
Output is correct |
64 |
Correct |
149 ms |
22000 KB |
Output is correct |
65 |
Correct |
148 ms |
21868 KB |
Output is correct |
66 |
Correct |
52 ms |
15644 KB |
Output is correct |
67 |
Correct |
132 ms |
22732 KB |
Output is correct |
68 |
Correct |
87 ms |
16840 KB |
Output is correct |
69 |
Correct |
56 ms |
15296 KB |
Output is correct |
70 |
Correct |
105 ms |
19188 KB |
Output is correct |
71 |
Correct |
6 ms |
11348 KB |
Output is correct |
72 |
Correct |
6 ms |
11348 KB |
Output is correct |
73 |
Correct |
6 ms |
11412 KB |
Output is correct |
74 |
Correct |
5 ms |
11348 KB |
Output is correct |
75 |
Correct |
5 ms |
11432 KB |
Output is correct |
76 |
Correct |
6 ms |
11344 KB |
Output is correct |
77 |
Correct |
30 ms |
11348 KB |
Output is correct |
78 |
Correct |
30 ms |
11348 KB |
Output is correct |
79 |
Correct |
29 ms |
11348 KB |
Output is correct |
80 |
Correct |
36 ms |
11424 KB |
Output is correct |
81 |
Correct |
109 ms |
15876 KB |
Output is correct |
82 |
Correct |
118 ms |
19300 KB |
Output is correct |
83 |
Correct |
123 ms |
19276 KB |
Output is correct |
84 |
Correct |
168 ms |
21620 KB |
Output is correct |
85 |
Correct |
171 ms |
24072 KB |
Output is correct |
86 |
Correct |
239 ms |
24448 KB |
Output is correct |
87 |
Correct |
248 ms |
24140 KB |
Output is correct |
88 |
Correct |
6 ms |
11452 KB |
Output is correct |
89 |
Correct |
259 ms |
24892 KB |
Output is correct |
90 |
Correct |
154 ms |
23224 KB |
Output is correct |
91 |
Correct |
146 ms |
23120 KB |
Output is correct |