답안 #163574

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
163574 2019-11-13T22:53:11 Z TadijaSebez Two Dishes (JOI19_dishes) C++11
100 / 100
8247 ms 254008 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N=1e6+50;
const int M=2*N;
const ll inf=3e18;
ll ckmx(ll &a, ll b){ return a=max(a,b);}
int ls[M],rs[M],tsz,root;
ll lzy[M][2],mx[M];
void Upd(int c, ll x, int t)
{
if(t==0)
{
mx[c]+=x,lzy[c][0]+=x,lzy[c][1]+=x;
}
else ckmx(mx[c],x),ckmx(lzy[c][1],x);
}
void Push(int c)
{
	Upd(ls[c],lzy[c][0],0);Upd(ls[c],lzy[c][1],1);
	Upd(rs[c],lzy[c][0],0);Upd(rs[c],lzy[c][1],1);
	lzy[c][0]=0;lzy[c][1]=-inf;
}
void Set(int c, int ss, int se, int qs, int qe, ll x, int t)
{
	if(qs>qe || qs>se || ss>qe) return;
	if(qs<=ss && qe>=se) return Upd(c,x,t);
	int mid=ss+se>>1;Push(c);
	Set(ls[c],ss,mid,qs,qe,x,t);
	Set(rs[c],mid+1,se,qs,qe,x,t);
	mx[c]=max(mx[ls[c]],mx[rs[c]]);
}
ll Get(int c, int ss, int se, int qi)
{
	if(ss==se) return mx[c];
	int mid=ss+se>>1;Push(c);
	return qi<=mid?Get(ls[c],ss,mid,qi):Get(rs[c],mid+1,se,qi);
}
void Build(int &c, int ss, int se)
{
	c=++tsz;mx[c]=lzy[c][0]=0;lzy[c][1]=-inf;
	if(ss==se) return;
	int mid=ss+se>>1;
	Build(ls[c],ss,mid);
	Build(rs[c],mid+1,se);
}
ll a[N],s[N],p[N],b[N],t[N],q[N];
vector<pair<int,ll>> Us[N];
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,m;
	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];
	for(int i=0;i<n;i++)
	{
		int j=upper_bound(b,b+m+1,s[i]-a[i+1])-b-1;
		if(j>=0) Us[j].pb({i+1,p[i]});
	}
	ll sum=0;
	for(int i=0;i<m;i++)
	{
		sum+=q[i];
		int j=upper_bound(a,a+n+1,t[i]-b[i+1])-a-1;
		if(j<n) Us[i].pb({j+1,-q[i]});
	}
	Build(root,0,n);
	for(int i=0;i<=m;i++)
	{
		for(auto u:Us[i]) Set(root,0,n,u.first,n,u.second,0);
		if(i==m) break;
		for(auto u:Us[i]) if(u.first) Set(root,0,n,u.first,n,Get(root,0,n,u.first-1),1);
	}
	cout<<sum+Get(root,0,n,n)<<endl;
	return 0;
}

Compilation message

dishes.cpp: In function 'void Set(int, int, int, int, int, long long int, int)':
dishes.cpp:29:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=ss+se>>1;Push(c);
          ~~^~~
dishes.cpp: In function 'long long int Get(int, int, int, int)':
dishes.cpp:37:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=ss+se>>1;Push(c);
          ~~^~~
dishes.cpp: In function 'void Build(int&, int, int)':
dishes.cpp:44:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=ss+se>>1;
          ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 834 ms 55672 KB Output is correct
2 Correct 823 ms 68652 KB Output is correct
3 Correct 385 ms 62560 KB Output is correct
4 Correct 664 ms 67228 KB Output is correct
5 Correct 24 ms 23928 KB Output is correct
6 Correct 718 ms 66668 KB Output is correct
7 Correct 153 ms 35960 KB Output is correct
8 Correct 259 ms 51508 KB Output is correct
9 Correct 393 ms 63520 KB Output is correct
10 Correct 789 ms 62840 KB Output is correct
11 Correct 305 ms 57016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 23932 KB Output is correct
2 Correct 24 ms 23992 KB Output is correct
3 Correct 24 ms 23900 KB Output is correct
4 Correct 45 ms 23928 KB Output is correct
5 Correct 25 ms 23928 KB Output is correct
6 Correct 27 ms 23928 KB Output is correct
7 Correct 26 ms 23928 KB Output is correct
8 Correct 27 ms 23928 KB Output is correct
9 Correct 25 ms 23892 KB Output is correct
10 Correct 24 ms 23928 KB Output is correct
11 Correct 26 ms 23928 KB Output is correct
12 Correct 26 ms 23928 KB Output is correct
13 Correct 25 ms 23928 KB Output is correct
14 Correct 24 ms 23928 KB Output is correct
15 Correct 25 ms 23928 KB Output is correct
16 Correct 24 ms 23928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 23932 KB Output is correct
2 Correct 24 ms 23992 KB Output is correct
3 Correct 24 ms 23900 KB Output is correct
4 Correct 45 ms 23928 KB Output is correct
5 Correct 25 ms 23928 KB Output is correct
6 Correct 27 ms 23928 KB Output is correct
7 Correct 26 ms 23928 KB Output is correct
8 Correct 27 ms 23928 KB Output is correct
9 Correct 25 ms 23892 KB Output is correct
10 Correct 24 ms 23928 KB Output is correct
11 Correct 26 ms 23928 KB Output is correct
12 Correct 26 ms 23928 KB Output is correct
13 Correct 25 ms 23928 KB Output is correct
14 Correct 24 ms 23928 KB Output is correct
15 Correct 25 ms 23928 KB Output is correct
16 Correct 24 ms 23928 KB Output is correct
17 Correct 29 ms 24184 KB Output is correct
18 Correct 28 ms 24184 KB Output is correct
19 Correct 29 ms 24184 KB Output is correct
20 Correct 28 ms 24184 KB Output is correct
21 Correct 30 ms 24184 KB Output is correct
22 Correct 29 ms 24184 KB Output is correct
23 Correct 30 ms 24184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 23932 KB Output is correct
2 Correct 24 ms 23992 KB Output is correct
3 Correct 24 ms 23900 KB Output is correct
4 Correct 45 ms 23928 KB Output is correct
5 Correct 25 ms 23928 KB Output is correct
6 Correct 27 ms 23928 KB Output is correct
7 Correct 26 ms 23928 KB Output is correct
8 Correct 27 ms 23928 KB Output is correct
9 Correct 25 ms 23892 KB Output is correct
10 Correct 24 ms 23928 KB Output is correct
11 Correct 26 ms 23928 KB Output is correct
12 Correct 26 ms 23928 KB Output is correct
13 Correct 25 ms 23928 KB Output is correct
14 Correct 24 ms 23928 KB Output is correct
15 Correct 25 ms 23928 KB Output is correct
16 Correct 24 ms 23928 KB Output is correct
17 Correct 29 ms 24184 KB Output is correct
18 Correct 28 ms 24184 KB Output is correct
19 Correct 29 ms 24184 KB Output is correct
20 Correct 28 ms 24184 KB Output is correct
21 Correct 30 ms 24184 KB Output is correct
22 Correct 29 ms 24184 KB Output is correct
23 Correct 30 ms 24184 KB Output is correct
24 Correct 534 ms 52192 KB Output is correct
25 Correct 613 ms 64400 KB Output is correct
26 Correct 556 ms 65500 KB Output is correct
27 Correct 605 ms 64424 KB Output is correct
28 Correct 562 ms 62296 KB Output is correct
29 Correct 357 ms 60384 KB Output is correct
30 Correct 1214 ms 66552 KB Output is correct
31 Correct 142 ms 37112 KB Output is correct
32 Correct 339 ms 49704 KB Output is correct
33 Correct 744 ms 63864 KB Output is correct
34 Correct 982 ms 65568 KB Output is correct
35 Correct 1144 ms 60152 KB Output is correct
36 Correct 1105 ms 60060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 23932 KB Output is correct
2 Correct 24 ms 23992 KB Output is correct
3 Correct 24 ms 23900 KB Output is correct
4 Correct 45 ms 23928 KB Output is correct
5 Correct 25 ms 23928 KB Output is correct
6 Correct 27 ms 23928 KB Output is correct
7 Correct 26 ms 23928 KB Output is correct
8 Correct 27 ms 23928 KB Output is correct
9 Correct 25 ms 23892 KB Output is correct
10 Correct 24 ms 23928 KB Output is correct
11 Correct 26 ms 23928 KB Output is correct
12 Correct 26 ms 23928 KB Output is correct
13 Correct 25 ms 23928 KB Output is correct
14 Correct 24 ms 23928 KB Output is correct
15 Correct 25 ms 23928 KB Output is correct
16 Correct 24 ms 23928 KB Output is correct
17 Correct 29 ms 24184 KB Output is correct
18 Correct 28 ms 24184 KB Output is correct
19 Correct 29 ms 24184 KB Output is correct
20 Correct 28 ms 24184 KB Output is correct
21 Correct 30 ms 24184 KB Output is correct
22 Correct 29 ms 24184 KB Output is correct
23 Correct 30 ms 24184 KB Output is correct
24 Correct 534 ms 52192 KB Output is correct
25 Correct 613 ms 64400 KB Output is correct
26 Correct 556 ms 65500 KB Output is correct
27 Correct 605 ms 64424 KB Output is correct
28 Correct 562 ms 62296 KB Output is correct
29 Correct 357 ms 60384 KB Output is correct
30 Correct 1214 ms 66552 KB Output is correct
31 Correct 142 ms 37112 KB Output is correct
32 Correct 339 ms 49704 KB Output is correct
33 Correct 744 ms 63864 KB Output is correct
34 Correct 982 ms 65568 KB Output is correct
35 Correct 1144 ms 60152 KB Output is correct
36 Correct 1105 ms 60060 KB Output is correct
37 Correct 596 ms 68620 KB Output is correct
38 Correct 627 ms 67532 KB Output is correct
39 Correct 840 ms 66416 KB Output is correct
40 Correct 850 ms 66412 KB Output is correct
41 Correct 23 ms 23928 KB Output is correct
42 Correct 1194 ms 69716 KB Output is correct
43 Correct 758 ms 66596 KB Output is correct
44 Correct 1302 ms 68332 KB Output is correct
45 Correct 1192 ms 63392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 23932 KB Output is correct
2 Correct 24 ms 23992 KB Output is correct
3 Correct 24 ms 23900 KB Output is correct
4 Correct 45 ms 23928 KB Output is correct
5 Correct 25 ms 23928 KB Output is correct
6 Correct 27 ms 23928 KB Output is correct
7 Correct 26 ms 23928 KB Output is correct
8 Correct 27 ms 23928 KB Output is correct
9 Correct 25 ms 23892 KB Output is correct
10 Correct 24 ms 23928 KB Output is correct
11 Correct 26 ms 23928 KB Output is correct
12 Correct 26 ms 23928 KB Output is correct
13 Correct 25 ms 23928 KB Output is correct
14 Correct 24 ms 23928 KB Output is correct
15 Correct 25 ms 23928 KB Output is correct
16 Correct 24 ms 23928 KB Output is correct
17 Correct 29 ms 24184 KB Output is correct
18 Correct 28 ms 24184 KB Output is correct
19 Correct 29 ms 24184 KB Output is correct
20 Correct 28 ms 24184 KB Output is correct
21 Correct 30 ms 24184 KB Output is correct
22 Correct 29 ms 24184 KB Output is correct
23 Correct 30 ms 24184 KB Output is correct
24 Correct 534 ms 52192 KB Output is correct
25 Correct 613 ms 64400 KB Output is correct
26 Correct 556 ms 65500 KB Output is correct
27 Correct 605 ms 64424 KB Output is correct
28 Correct 562 ms 62296 KB Output is correct
29 Correct 357 ms 60384 KB Output is correct
30 Correct 1214 ms 66552 KB Output is correct
31 Correct 142 ms 37112 KB Output is correct
32 Correct 339 ms 49704 KB Output is correct
33 Correct 744 ms 63864 KB Output is correct
34 Correct 982 ms 65568 KB Output is correct
35 Correct 1144 ms 60152 KB Output is correct
36 Correct 1105 ms 60060 KB Output is correct
37 Correct 596 ms 68620 KB Output is correct
38 Correct 627 ms 67532 KB Output is correct
39 Correct 840 ms 66416 KB Output is correct
40 Correct 850 ms 66412 KB Output is correct
41 Correct 23 ms 23928 KB Output is correct
42 Correct 1194 ms 69716 KB Output is correct
43 Correct 758 ms 66596 KB Output is correct
44 Correct 1302 ms 68332 KB Output is correct
45 Correct 1192 ms 63392 KB Output is correct
46 Correct 3120 ms 248400 KB Output is correct
47 Correct 3431 ms 242900 KB Output is correct
48 Correct 4720 ms 236940 KB Output is correct
49 Correct 4596 ms 236980 KB Output is correct
50 Correct 8077 ms 253776 KB Output is correct
51 Correct 4458 ms 233776 KB Output is correct
52 Correct 5981 ms 240232 KB Output is correct
53 Correct 7451 ms 221676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 834 ms 55672 KB Output is correct
2 Correct 823 ms 68652 KB Output is correct
3 Correct 385 ms 62560 KB Output is correct
4 Correct 664 ms 67228 KB Output is correct
5 Correct 24 ms 23928 KB Output is correct
6 Correct 718 ms 66668 KB Output is correct
7 Correct 153 ms 35960 KB Output is correct
8 Correct 259 ms 51508 KB Output is correct
9 Correct 393 ms 63520 KB Output is correct
10 Correct 789 ms 62840 KB Output is correct
11 Correct 305 ms 57016 KB Output is correct
12 Correct 29 ms 23932 KB Output is correct
13 Correct 24 ms 23992 KB Output is correct
14 Correct 24 ms 23900 KB Output is correct
15 Correct 45 ms 23928 KB Output is correct
16 Correct 25 ms 23928 KB Output is correct
17 Correct 27 ms 23928 KB Output is correct
18 Correct 26 ms 23928 KB Output is correct
19 Correct 27 ms 23928 KB Output is correct
20 Correct 25 ms 23892 KB Output is correct
21 Correct 24 ms 23928 KB Output is correct
22 Correct 26 ms 23928 KB Output is correct
23 Correct 26 ms 23928 KB Output is correct
24 Correct 25 ms 23928 KB Output is correct
25 Correct 24 ms 23928 KB Output is correct
26 Correct 25 ms 23928 KB Output is correct
27 Correct 24 ms 23928 KB Output is correct
28 Correct 29 ms 24184 KB Output is correct
29 Correct 28 ms 24184 KB Output is correct
30 Correct 29 ms 24184 KB Output is correct
31 Correct 28 ms 24184 KB Output is correct
32 Correct 30 ms 24184 KB Output is correct
33 Correct 29 ms 24184 KB Output is correct
34 Correct 30 ms 24184 KB Output is correct
35 Correct 534 ms 52192 KB Output is correct
36 Correct 613 ms 64400 KB Output is correct
37 Correct 556 ms 65500 KB Output is correct
38 Correct 605 ms 64424 KB Output is correct
39 Correct 562 ms 62296 KB Output is correct
40 Correct 357 ms 60384 KB Output is correct
41 Correct 1214 ms 66552 KB Output is correct
42 Correct 142 ms 37112 KB Output is correct
43 Correct 339 ms 49704 KB Output is correct
44 Correct 744 ms 63864 KB Output is correct
45 Correct 982 ms 65568 KB Output is correct
46 Correct 1144 ms 60152 KB Output is correct
47 Correct 1105 ms 60060 KB Output is correct
48 Correct 596 ms 68620 KB Output is correct
49 Correct 627 ms 67532 KB Output is correct
50 Correct 840 ms 66416 KB Output is correct
51 Correct 850 ms 66412 KB Output is correct
52 Correct 23 ms 23928 KB Output is correct
53 Correct 1194 ms 69716 KB Output is correct
54 Correct 758 ms 66596 KB Output is correct
55 Correct 1302 ms 68332 KB Output is correct
56 Correct 1192 ms 63392 KB Output is correct
57 Correct 591 ms 69100 KB Output is correct
58 Correct 629 ms 67916 KB Output is correct
59 Correct 873 ms 67388 KB Output is correct
60 Correct 878 ms 67448 KB Output is correct
61 Correct 1201 ms 66808 KB Output is correct
62 Correct 24 ms 23928 KB Output is correct
63 Correct 1190 ms 69752 KB Output is correct
64 Correct 739 ms 66936 KB Output is correct
65 Correct 951 ms 67540 KB Output is correct
66 Correct 1115 ms 63224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 834 ms 55672 KB Output is correct
2 Correct 823 ms 68652 KB Output is correct
3 Correct 385 ms 62560 KB Output is correct
4 Correct 664 ms 67228 KB Output is correct
5 Correct 24 ms 23928 KB Output is correct
6 Correct 718 ms 66668 KB Output is correct
7 Correct 153 ms 35960 KB Output is correct
8 Correct 259 ms 51508 KB Output is correct
9 Correct 393 ms 63520 KB Output is correct
10 Correct 789 ms 62840 KB Output is correct
11 Correct 305 ms 57016 KB Output is correct
12 Correct 29 ms 23932 KB Output is correct
13 Correct 24 ms 23992 KB Output is correct
14 Correct 24 ms 23900 KB Output is correct
15 Correct 45 ms 23928 KB Output is correct
16 Correct 25 ms 23928 KB Output is correct
17 Correct 27 ms 23928 KB Output is correct
18 Correct 26 ms 23928 KB Output is correct
19 Correct 27 ms 23928 KB Output is correct
20 Correct 25 ms 23892 KB Output is correct
21 Correct 24 ms 23928 KB Output is correct
22 Correct 26 ms 23928 KB Output is correct
23 Correct 26 ms 23928 KB Output is correct
24 Correct 25 ms 23928 KB Output is correct
25 Correct 24 ms 23928 KB Output is correct
26 Correct 25 ms 23928 KB Output is correct
27 Correct 24 ms 23928 KB Output is correct
28 Correct 29 ms 24184 KB Output is correct
29 Correct 28 ms 24184 KB Output is correct
30 Correct 29 ms 24184 KB Output is correct
31 Correct 28 ms 24184 KB Output is correct
32 Correct 30 ms 24184 KB Output is correct
33 Correct 29 ms 24184 KB Output is correct
34 Correct 30 ms 24184 KB Output is correct
35 Correct 534 ms 52192 KB Output is correct
36 Correct 613 ms 64400 KB Output is correct
37 Correct 556 ms 65500 KB Output is correct
38 Correct 605 ms 64424 KB Output is correct
39 Correct 562 ms 62296 KB Output is correct
40 Correct 357 ms 60384 KB Output is correct
41 Correct 1214 ms 66552 KB Output is correct
42 Correct 142 ms 37112 KB Output is correct
43 Correct 339 ms 49704 KB Output is correct
44 Correct 744 ms 63864 KB Output is correct
45 Correct 982 ms 65568 KB Output is correct
46 Correct 1144 ms 60152 KB Output is correct
47 Correct 1105 ms 60060 KB Output is correct
48 Correct 596 ms 68620 KB Output is correct
49 Correct 627 ms 67532 KB Output is correct
50 Correct 840 ms 66416 KB Output is correct
51 Correct 850 ms 66412 KB Output is correct
52 Correct 23 ms 23928 KB Output is correct
53 Correct 1194 ms 69716 KB Output is correct
54 Correct 758 ms 66596 KB Output is correct
55 Correct 1302 ms 68332 KB Output is correct
56 Correct 1192 ms 63392 KB Output is correct
57 Correct 3120 ms 248400 KB Output is correct
58 Correct 3431 ms 242900 KB Output is correct
59 Correct 4720 ms 236940 KB Output is correct
60 Correct 4596 ms 236980 KB Output is correct
61 Correct 8077 ms 253776 KB Output is correct
62 Correct 4458 ms 233776 KB Output is correct
63 Correct 5981 ms 240232 KB Output is correct
64 Correct 7451 ms 221676 KB Output is correct
65 Correct 591 ms 69100 KB Output is correct
66 Correct 629 ms 67916 KB Output is correct
67 Correct 873 ms 67388 KB Output is correct
68 Correct 878 ms 67448 KB Output is correct
69 Correct 1201 ms 66808 KB Output is correct
70 Correct 24 ms 23928 KB Output is correct
71 Correct 1190 ms 69752 KB Output is correct
72 Correct 739 ms 66936 KB Output is correct
73 Correct 951 ms 67540 KB Output is correct
74 Correct 1115 ms 63224 KB Output is correct
75 Correct 3399 ms 249700 KB Output is correct
76 Correct 3378 ms 244184 KB Output is correct
77 Correct 4688 ms 238736 KB Output is correct
78 Correct 4711 ms 238724 KB Output is correct
79 Correct 8247 ms 254008 KB Output is correct
80 Correct 4579 ms 237624 KB Output is correct
81 Correct 5860 ms 231180 KB Output is correct
82 Correct 7759 ms 221816 KB Output is correct
83 Correct 7730 ms 240560 KB Output is correct