#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxN=1e6;
int n, m, p[mxN], q[mxN];
ll a[mxN+1], b[mxN+1], s[mxN], t[mxN], ans, lz[1<<21];
vector<array<ll, 3>> e;
array<ll, 2> st[1<<21];
void app(int i, ll x) {
st[i][0]+=x;
st[i][1]+=x;
lz[i]+=x;
}
void psh(int i) {
app(2*i, lz[i]);
app(2*i+1, lz[i]);
lz[i]=0;
}
void upd1(int l1, int r1, ll x, int i=1, int l2=0, int r2=m) {
if(l1<=l2&&r2<=r1) {
app(i, x);
return;
}
int m2=(l2+r2)/2;
psh(i);
if(l1<=m2)
upd1(l1, r1, x, 2*i, l2, m2);
if(m2<r1)
upd1(l1, r1, x, 2*i+1, m2+1, r2);
st[i][0]=min(st[2*i][0], st[2*i+1][0]);
st[i][1]=max(st[2*i][1], st[2*i+1][1]);
}
void upd2(int l1, int r1, ll x, int i=1, int l2=0, int r2=m) {
if(st[i][0]>=x)
return;
if(l1<=l2&&r2<=r1&&st[i][0]==st[i][1]) {
app(i, x-st[i][0]);
return;
}
int m2=(l2+r2)/2;
psh(i);
if(l1<=m2)
upd2(l1, r1, x, 2*i, l2, m2);
if(m2<r1)
upd2(l1, r1, x, 2*i+1, m2+1, r2);
st[i][0]=min(st[2*i][0], st[2*i+1][0]);
st[i][1]=max(st[2*i][1], st[2*i+1][1]);
}
ll qry(int l1, int i=1, int l2=0, int r2=m) {
if(l2==r2)
return st[i][0];
int m2=(l2+r2)/2;
psh(i);
return l1<=m2?qry(l1, 2*i, l2, m2):qry(l1, 2*i+1, m2+1, r2);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i=0; i<n; ++i)
cin >> a[i+1] >> s[i] >> p[i], a[i+1]+=a[i];
for(int i=0; i<m; ++i) {
cin >> b[i+1] >> t[i] >> q[i], b[i+1]+=b[i];
e.push_back({upper_bound(a, a+n+1, t[i]-b[i+1])-a, -i, -q[i]});
if(e.back()[0])
ans+=q[i];
else
e.pop_back();
}
for(int i=0; i<n; ++i) {
int j=upper_bound(b, b+m+1, s[i]-a[i+1])-b;
if(j)
e.push_back({i+1, -j+1, p[i]});
}
sort(e.begin(), e.end());
for(array<ll, 3> f : e) {
upd1(0, -f[1], f[2]);
upd2(-f[1], m, qry(-f[1]));
}
cout << ans+qry(m);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
426 ms |
28848 KB |
Output is correct |
2 |
Correct |
446 ms |
30524 KB |
Output is correct |
3 |
Correct |
426 ms |
30664 KB |
Output is correct |
4 |
Correct |
366 ms |
22308 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
415 ms |
30024 KB |
Output is correct |
7 |
Correct |
190 ms |
20440 KB |
Output is correct |
8 |
Correct |
118 ms |
11240 KB |
Output is correct |
9 |
Correct |
372 ms |
30664 KB |
Output is correct |
10 |
Correct |
389 ms |
30880 KB |
Output is correct |
11 |
Correct |
318 ms |
30792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
6 ms |
896 KB |
Output is correct |
18 |
Correct |
5 ms |
896 KB |
Output is correct |
19 |
Correct |
7 ms |
896 KB |
Output is correct |
20 |
Correct |
5 ms |
768 KB |
Output is correct |
21 |
Correct |
6 ms |
896 KB |
Output is correct |
22 |
Correct |
7 ms |
768 KB |
Output is correct |
23 |
Correct |
5 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
6 ms |
896 KB |
Output is correct |
18 |
Correct |
5 ms |
896 KB |
Output is correct |
19 |
Correct |
7 ms |
896 KB |
Output is correct |
20 |
Correct |
5 ms |
768 KB |
Output is correct |
21 |
Correct |
6 ms |
896 KB |
Output is correct |
22 |
Correct |
7 ms |
768 KB |
Output is correct |
23 |
Correct |
5 ms |
768 KB |
Output is correct |
24 |
Correct |
441 ms |
28488 KB |
Output is correct |
25 |
Correct |
394 ms |
28284 KB |
Output is correct |
26 |
Correct |
358 ms |
28364 KB |
Output is correct |
27 |
Correct |
383 ms |
28420 KB |
Output is correct |
28 |
Correct |
472 ms |
29640 KB |
Output is correct |
29 |
Correct |
353 ms |
30736 KB |
Output is correct |
30 |
Correct |
880 ms |
30536 KB |
Output is correct |
31 |
Correct |
275 ms |
22104 KB |
Output is correct |
32 |
Correct |
102 ms |
11240 KB |
Output is correct |
33 |
Correct |
516 ms |
25920 KB |
Output is correct |
34 |
Correct |
706 ms |
30384 KB |
Output is correct |
35 |
Correct |
752 ms |
30536 KB |
Output is correct |
36 |
Correct |
757 ms |
30408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
6 ms |
896 KB |
Output is correct |
18 |
Correct |
5 ms |
896 KB |
Output is correct |
19 |
Correct |
7 ms |
896 KB |
Output is correct |
20 |
Correct |
5 ms |
768 KB |
Output is correct |
21 |
Correct |
6 ms |
896 KB |
Output is correct |
22 |
Correct |
7 ms |
768 KB |
Output is correct |
23 |
Correct |
5 ms |
768 KB |
Output is correct |
24 |
Correct |
441 ms |
28488 KB |
Output is correct |
25 |
Correct |
394 ms |
28284 KB |
Output is correct |
26 |
Correct |
358 ms |
28364 KB |
Output is correct |
27 |
Correct |
383 ms |
28420 KB |
Output is correct |
28 |
Correct |
472 ms |
29640 KB |
Output is correct |
29 |
Correct |
353 ms |
30736 KB |
Output is correct |
30 |
Correct |
880 ms |
30536 KB |
Output is correct |
31 |
Correct |
275 ms |
22104 KB |
Output is correct |
32 |
Correct |
102 ms |
11240 KB |
Output is correct |
33 |
Correct |
516 ms |
25920 KB |
Output is correct |
34 |
Correct |
706 ms |
30384 KB |
Output is correct |
35 |
Correct |
752 ms |
30536 KB |
Output is correct |
36 |
Correct |
757 ms |
30408 KB |
Output is correct |
37 |
Correct |
434 ms |
28488 KB |
Output is correct |
38 |
Correct |
432 ms |
28504 KB |
Output is correct |
39 |
Correct |
482 ms |
30848 KB |
Output is correct |
40 |
Correct |
537 ms |
30664 KB |
Output is correct |
41 |
Correct |
2 ms |
384 KB |
Output is correct |
42 |
Correct |
872 ms |
30732 KB |
Output is correct |
43 |
Correct |
553 ms |
25944 KB |
Output is correct |
44 |
Correct |
661 ms |
30408 KB |
Output is correct |
45 |
Correct |
803 ms |
30680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
6 ms |
896 KB |
Output is correct |
18 |
Correct |
5 ms |
896 KB |
Output is correct |
19 |
Correct |
7 ms |
896 KB |
Output is correct |
20 |
Correct |
5 ms |
768 KB |
Output is correct |
21 |
Correct |
6 ms |
896 KB |
Output is correct |
22 |
Correct |
7 ms |
768 KB |
Output is correct |
23 |
Correct |
5 ms |
768 KB |
Output is correct |
24 |
Correct |
441 ms |
28488 KB |
Output is correct |
25 |
Correct |
394 ms |
28284 KB |
Output is correct |
26 |
Correct |
358 ms |
28364 KB |
Output is correct |
27 |
Correct |
383 ms |
28420 KB |
Output is correct |
28 |
Correct |
472 ms |
29640 KB |
Output is correct |
29 |
Correct |
353 ms |
30736 KB |
Output is correct |
30 |
Correct |
880 ms |
30536 KB |
Output is correct |
31 |
Correct |
275 ms |
22104 KB |
Output is correct |
32 |
Correct |
102 ms |
11240 KB |
Output is correct |
33 |
Correct |
516 ms |
25920 KB |
Output is correct |
34 |
Correct |
706 ms |
30384 KB |
Output is correct |
35 |
Correct |
752 ms |
30536 KB |
Output is correct |
36 |
Correct |
757 ms |
30408 KB |
Output is correct |
37 |
Correct |
434 ms |
28488 KB |
Output is correct |
38 |
Correct |
432 ms |
28504 KB |
Output is correct |
39 |
Correct |
482 ms |
30848 KB |
Output is correct |
40 |
Correct |
537 ms |
30664 KB |
Output is correct |
41 |
Correct |
2 ms |
384 KB |
Output is correct |
42 |
Correct |
872 ms |
30732 KB |
Output is correct |
43 |
Correct |
553 ms |
25944 KB |
Output is correct |
44 |
Correct |
661 ms |
30408 KB |
Output is correct |
45 |
Correct |
803 ms |
30680 KB |
Output is correct |
46 |
Correct |
2369 ms |
124372 KB |
Output is correct |
47 |
Correct |
2066 ms |
124312 KB |
Output is correct |
48 |
Correct |
2268 ms |
135956 KB |
Output is correct |
49 |
Correct |
3152 ms |
136284 KB |
Output is correct |
50 |
Correct |
5754 ms |
136176 KB |
Output is correct |
51 |
Correct |
3460 ms |
111124 KB |
Output is correct |
52 |
Correct |
3925 ms |
131408 KB |
Output is correct |
53 |
Correct |
5043 ms |
135164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
426 ms |
28848 KB |
Output is correct |
2 |
Correct |
446 ms |
30524 KB |
Output is correct |
3 |
Correct |
426 ms |
30664 KB |
Output is correct |
4 |
Correct |
366 ms |
22308 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
415 ms |
30024 KB |
Output is correct |
7 |
Correct |
190 ms |
20440 KB |
Output is correct |
8 |
Correct |
118 ms |
11240 KB |
Output is correct |
9 |
Correct |
372 ms |
30664 KB |
Output is correct |
10 |
Correct |
389 ms |
30880 KB |
Output is correct |
11 |
Correct |
318 ms |
30792 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
3 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
6 ms |
896 KB |
Output is correct |
29 |
Correct |
5 ms |
896 KB |
Output is correct |
30 |
Correct |
7 ms |
896 KB |
Output is correct |
31 |
Correct |
5 ms |
768 KB |
Output is correct |
32 |
Correct |
6 ms |
896 KB |
Output is correct |
33 |
Correct |
7 ms |
768 KB |
Output is correct |
34 |
Correct |
5 ms |
768 KB |
Output is correct |
35 |
Correct |
441 ms |
28488 KB |
Output is correct |
36 |
Correct |
394 ms |
28284 KB |
Output is correct |
37 |
Correct |
358 ms |
28364 KB |
Output is correct |
38 |
Correct |
383 ms |
28420 KB |
Output is correct |
39 |
Correct |
472 ms |
29640 KB |
Output is correct |
40 |
Correct |
353 ms |
30736 KB |
Output is correct |
41 |
Correct |
880 ms |
30536 KB |
Output is correct |
42 |
Correct |
275 ms |
22104 KB |
Output is correct |
43 |
Correct |
102 ms |
11240 KB |
Output is correct |
44 |
Correct |
516 ms |
25920 KB |
Output is correct |
45 |
Correct |
706 ms |
30384 KB |
Output is correct |
46 |
Correct |
752 ms |
30536 KB |
Output is correct |
47 |
Correct |
757 ms |
30408 KB |
Output is correct |
48 |
Correct |
434 ms |
28488 KB |
Output is correct |
49 |
Correct |
432 ms |
28504 KB |
Output is correct |
50 |
Correct |
482 ms |
30848 KB |
Output is correct |
51 |
Correct |
537 ms |
30664 KB |
Output is correct |
52 |
Correct |
2 ms |
384 KB |
Output is correct |
53 |
Correct |
872 ms |
30732 KB |
Output is correct |
54 |
Correct |
553 ms |
25944 KB |
Output is correct |
55 |
Correct |
661 ms |
30408 KB |
Output is correct |
56 |
Correct |
803 ms |
30680 KB |
Output is correct |
57 |
Incorrect |
444 ms |
28352 KB |
Output isn't correct |
58 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
426 ms |
28848 KB |
Output is correct |
2 |
Correct |
446 ms |
30524 KB |
Output is correct |
3 |
Correct |
426 ms |
30664 KB |
Output is correct |
4 |
Correct |
366 ms |
22308 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
415 ms |
30024 KB |
Output is correct |
7 |
Correct |
190 ms |
20440 KB |
Output is correct |
8 |
Correct |
118 ms |
11240 KB |
Output is correct |
9 |
Correct |
372 ms |
30664 KB |
Output is correct |
10 |
Correct |
389 ms |
30880 KB |
Output is correct |
11 |
Correct |
318 ms |
30792 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
3 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
6 ms |
896 KB |
Output is correct |
29 |
Correct |
5 ms |
896 KB |
Output is correct |
30 |
Correct |
7 ms |
896 KB |
Output is correct |
31 |
Correct |
5 ms |
768 KB |
Output is correct |
32 |
Correct |
6 ms |
896 KB |
Output is correct |
33 |
Correct |
7 ms |
768 KB |
Output is correct |
34 |
Correct |
5 ms |
768 KB |
Output is correct |
35 |
Correct |
441 ms |
28488 KB |
Output is correct |
36 |
Correct |
394 ms |
28284 KB |
Output is correct |
37 |
Correct |
358 ms |
28364 KB |
Output is correct |
38 |
Correct |
383 ms |
28420 KB |
Output is correct |
39 |
Correct |
472 ms |
29640 KB |
Output is correct |
40 |
Correct |
353 ms |
30736 KB |
Output is correct |
41 |
Correct |
880 ms |
30536 KB |
Output is correct |
42 |
Correct |
275 ms |
22104 KB |
Output is correct |
43 |
Correct |
102 ms |
11240 KB |
Output is correct |
44 |
Correct |
516 ms |
25920 KB |
Output is correct |
45 |
Correct |
706 ms |
30384 KB |
Output is correct |
46 |
Correct |
752 ms |
30536 KB |
Output is correct |
47 |
Correct |
757 ms |
30408 KB |
Output is correct |
48 |
Correct |
434 ms |
28488 KB |
Output is correct |
49 |
Correct |
432 ms |
28504 KB |
Output is correct |
50 |
Correct |
482 ms |
30848 KB |
Output is correct |
51 |
Correct |
537 ms |
30664 KB |
Output is correct |
52 |
Correct |
2 ms |
384 KB |
Output is correct |
53 |
Correct |
872 ms |
30732 KB |
Output is correct |
54 |
Correct |
553 ms |
25944 KB |
Output is correct |
55 |
Correct |
661 ms |
30408 KB |
Output is correct |
56 |
Correct |
803 ms |
30680 KB |
Output is correct |
57 |
Correct |
2369 ms |
124372 KB |
Output is correct |
58 |
Correct |
2066 ms |
124312 KB |
Output is correct |
59 |
Correct |
2268 ms |
135956 KB |
Output is correct |
60 |
Correct |
3152 ms |
136284 KB |
Output is correct |
61 |
Correct |
5754 ms |
136176 KB |
Output is correct |
62 |
Correct |
3460 ms |
111124 KB |
Output is correct |
63 |
Correct |
3925 ms |
131408 KB |
Output is correct |
64 |
Correct |
5043 ms |
135164 KB |
Output is correct |
65 |
Incorrect |
444 ms |
28352 KB |
Output isn't correct |
66 |
Halted |
0 ms |
0 KB |
- |