Submission #347113

# Submission time Handle Problem Language Result Execution time Memory
347113 2021-01-11T20:07:43 Z YJU Two Dishes (JOI19_dishes) C++14
100 / 100
3204 ms 236824 KB
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=1e6+5;
const ld pi=acos(-1);
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
 
ll n,m,a[N],s[N],p[N],b[N],t[N],q[N],ans,f[N];
vector<ll> ea[N],lis;
set<ll> ms;
 
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>m;
	REP1(i,n)cin>>a[i]>>s[i]>>p[i],a[i]+=a[i-1];
	REP1(i,m)cin>>b[i]>>t[i]>>q[i],b[i]+=b[i-1];
	
	REP1(i,m){
		ea[lwb(a,a+n+1,t[i]-b[i]+1)-a+1].pb(i);
	}
	
	REP1(i,m)f[i]=(i==1?-INF:0)-q[i],ans+=q[i],ms.insert(i),lis.pb(i);
	
	REP1(i,n+1){
		
		for(auto j:ea[i])f[j]+=q[j],ans-=q[j],lis.pb(j),ms.insert(j);
		
		/*REP1(j,m){
			//cout<<f[j]<<(j==m?"\n":" ");
			if(f[j]<0){f[j+1]+=f[j];f[j]=0;}
		}*/
		
		//REP1(j,m)cout<<f[j]<<(j==m?"\n":" ");
		
		sort(lis.begin(),lis.end());
		lis.resize(unique(lis.begin(),lis.end())-lis.begin());
		
		for(auto j:lis){
			auto l=ms.lwb(j),r=l;
			ll lst=0;
			while(r!=ms.end()){
				f[*r]+=lst;
				if(f[*r]>=0)break;
				lst=f[*r],f[*r++]=0;
			}
			ms.erase(l,r);
		}
		
		//REP1(j,m)cout<<f[j]<<(j==m?"\n":" ");
		lis.clear();
		if(i==n+1)break;
		ll id=lwb(b+1,b+m+1,s[i]-a[i]+1)-b;
		if(s[i]-a[i]<b[0])id=0;
		f[0]+=p[i];f[id]-=p[i];
		if(id)ms.insert(id),lis.pb(id);
	}
	
	REP(i,m+1)ans+=f[i];
	cout<<ans<<"\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 325 ms 51680 KB Output is correct
2 Correct 288 ms 53856 KB Output is correct
3 Correct 256 ms 51556 KB Output is correct
4 Correct 322 ms 56676 KB Output is correct
5 Correct 16 ms 24044 KB Output is correct
6 Correct 296 ms 52324 KB Output is correct
7 Correct 163 ms 48484 KB Output is correct
8 Correct 115 ms 34156 KB Output is correct
9 Correct 264 ms 51556 KB Output is correct
10 Correct 256 ms 57696 KB Output is correct
11 Correct 208 ms 53092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23916 KB Output is correct
2 Correct 16 ms 23916 KB Output is correct
3 Correct 16 ms 23916 KB Output is correct
4 Correct 16 ms 23916 KB Output is correct
5 Correct 16 ms 23916 KB Output is correct
6 Correct 16 ms 23916 KB Output is correct
7 Correct 16 ms 23916 KB Output is correct
8 Correct 16 ms 23916 KB Output is correct
9 Correct 16 ms 23916 KB Output is correct
10 Correct 16 ms 23916 KB Output is correct
11 Correct 16 ms 23916 KB Output is correct
12 Correct 17 ms 23916 KB Output is correct
13 Correct 16 ms 23916 KB Output is correct
14 Correct 16 ms 23916 KB Output is correct
15 Correct 17 ms 23916 KB Output is correct
16 Correct 16 ms 23916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23916 KB Output is correct
2 Correct 16 ms 23916 KB Output is correct
3 Correct 16 ms 23916 KB Output is correct
4 Correct 16 ms 23916 KB Output is correct
5 Correct 16 ms 23916 KB Output is correct
6 Correct 16 ms 23916 KB Output is correct
7 Correct 16 ms 23916 KB Output is correct
8 Correct 16 ms 23916 KB Output is correct
9 Correct 16 ms 23916 KB Output is correct
10 Correct 16 ms 23916 KB Output is correct
11 Correct 16 ms 23916 KB Output is correct
12 Correct 17 ms 23916 KB Output is correct
13 Correct 16 ms 23916 KB Output is correct
14 Correct 16 ms 23916 KB Output is correct
15 Correct 17 ms 23916 KB Output is correct
16 Correct 16 ms 23916 KB Output is correct
17 Correct 19 ms 24300 KB Output is correct
18 Correct 19 ms 24172 KB Output is correct
19 Correct 20 ms 24300 KB Output is correct
20 Correct 19 ms 24300 KB Output is correct
21 Correct 19 ms 24172 KB Output is correct
22 Correct 19 ms 24172 KB Output is correct
23 Correct 19 ms 24172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23916 KB Output is correct
2 Correct 16 ms 23916 KB Output is correct
3 Correct 16 ms 23916 KB Output is correct
4 Correct 16 ms 23916 KB Output is correct
5 Correct 16 ms 23916 KB Output is correct
6 Correct 16 ms 23916 KB Output is correct
7 Correct 16 ms 23916 KB Output is correct
8 Correct 16 ms 23916 KB Output is correct
9 Correct 16 ms 23916 KB Output is correct
10 Correct 16 ms 23916 KB Output is correct
11 Correct 16 ms 23916 KB Output is correct
12 Correct 17 ms 23916 KB Output is correct
13 Correct 16 ms 23916 KB Output is correct
14 Correct 16 ms 23916 KB Output is correct
15 Correct 17 ms 23916 KB Output is correct
16 Correct 16 ms 23916 KB Output is correct
17 Correct 19 ms 24300 KB Output is correct
18 Correct 19 ms 24172 KB Output is correct
19 Correct 20 ms 24300 KB Output is correct
20 Correct 19 ms 24300 KB Output is correct
21 Correct 19 ms 24172 KB Output is correct
22 Correct 19 ms 24172 KB Output is correct
23 Correct 19 ms 24172 KB Output is correct
24 Correct 258 ms 53972 KB Output is correct
25 Correct 337 ms 57956 KB Output is correct
26 Correct 268 ms 60756 KB Output is correct
27 Correct 314 ms 62688 KB Output is correct
28 Correct 320 ms 59356 KB Output is correct
29 Correct 240 ms 58724 KB Output is correct
30 Correct 480 ms 60764 KB Output is correct
31 Correct 172 ms 48108 KB Output is correct
32 Correct 98 ms 33772 KB Output is correct
33 Correct 378 ms 62044 KB Output is correct
34 Correct 413 ms 58844 KB Output is correct
35 Correct 423 ms 54236 KB Output is correct
36 Correct 434 ms 54368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23916 KB Output is correct
2 Correct 16 ms 23916 KB Output is correct
3 Correct 16 ms 23916 KB Output is correct
4 Correct 16 ms 23916 KB Output is correct
5 Correct 16 ms 23916 KB Output is correct
6 Correct 16 ms 23916 KB Output is correct
7 Correct 16 ms 23916 KB Output is correct
8 Correct 16 ms 23916 KB Output is correct
9 Correct 16 ms 23916 KB Output is correct
10 Correct 16 ms 23916 KB Output is correct
11 Correct 16 ms 23916 KB Output is correct
12 Correct 17 ms 23916 KB Output is correct
13 Correct 16 ms 23916 KB Output is correct
14 Correct 16 ms 23916 KB Output is correct
15 Correct 17 ms 23916 KB Output is correct
16 Correct 16 ms 23916 KB Output is correct
17 Correct 19 ms 24300 KB Output is correct
18 Correct 19 ms 24172 KB Output is correct
19 Correct 20 ms 24300 KB Output is correct
20 Correct 19 ms 24300 KB Output is correct
21 Correct 19 ms 24172 KB Output is correct
22 Correct 19 ms 24172 KB Output is correct
23 Correct 19 ms 24172 KB Output is correct
24 Correct 258 ms 53972 KB Output is correct
25 Correct 337 ms 57956 KB Output is correct
26 Correct 268 ms 60756 KB Output is correct
27 Correct 314 ms 62688 KB Output is correct
28 Correct 320 ms 59356 KB Output is correct
29 Correct 240 ms 58724 KB Output is correct
30 Correct 480 ms 60764 KB Output is correct
31 Correct 172 ms 48108 KB Output is correct
32 Correct 98 ms 33772 KB Output is correct
33 Correct 378 ms 62044 KB Output is correct
34 Correct 413 ms 58844 KB Output is correct
35 Correct 423 ms 54236 KB Output is correct
36 Correct 434 ms 54368 KB Output is correct
37 Correct 299 ms 63700 KB Output is correct
38 Correct 328 ms 65760 KB Output is correct
39 Correct 340 ms 63072 KB Output is correct
40 Correct 271 ms 63328 KB Output is correct
41 Correct 16 ms 23916 KB Output is correct
42 Correct 510 ms 63944 KB Output is correct
43 Correct 404 ms 65008 KB Output is correct
44 Correct 435 ms 61680 KB Output is correct
45 Correct 450 ms 57572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23916 KB Output is correct
2 Correct 16 ms 23916 KB Output is correct
3 Correct 16 ms 23916 KB Output is correct
4 Correct 16 ms 23916 KB Output is correct
5 Correct 16 ms 23916 KB Output is correct
6 Correct 16 ms 23916 KB Output is correct
7 Correct 16 ms 23916 KB Output is correct
8 Correct 16 ms 23916 KB Output is correct
9 Correct 16 ms 23916 KB Output is correct
10 Correct 16 ms 23916 KB Output is correct
11 Correct 16 ms 23916 KB Output is correct
12 Correct 17 ms 23916 KB Output is correct
13 Correct 16 ms 23916 KB Output is correct
14 Correct 16 ms 23916 KB Output is correct
15 Correct 17 ms 23916 KB Output is correct
16 Correct 16 ms 23916 KB Output is correct
17 Correct 19 ms 24300 KB Output is correct
18 Correct 19 ms 24172 KB Output is correct
19 Correct 20 ms 24300 KB Output is correct
20 Correct 19 ms 24300 KB Output is correct
21 Correct 19 ms 24172 KB Output is correct
22 Correct 19 ms 24172 KB Output is correct
23 Correct 19 ms 24172 KB Output is correct
24 Correct 258 ms 53972 KB Output is correct
25 Correct 337 ms 57956 KB Output is correct
26 Correct 268 ms 60756 KB Output is correct
27 Correct 314 ms 62688 KB Output is correct
28 Correct 320 ms 59356 KB Output is correct
29 Correct 240 ms 58724 KB Output is correct
30 Correct 480 ms 60764 KB Output is correct
31 Correct 172 ms 48108 KB Output is correct
32 Correct 98 ms 33772 KB Output is correct
33 Correct 378 ms 62044 KB Output is correct
34 Correct 413 ms 58844 KB Output is correct
35 Correct 423 ms 54236 KB Output is correct
36 Correct 434 ms 54368 KB Output is correct
37 Correct 299 ms 63700 KB Output is correct
38 Correct 328 ms 65760 KB Output is correct
39 Correct 340 ms 63072 KB Output is correct
40 Correct 271 ms 63328 KB Output is correct
41 Correct 16 ms 23916 KB Output is correct
42 Correct 510 ms 63944 KB Output is correct
43 Correct 404 ms 65008 KB Output is correct
44 Correct 435 ms 61680 KB Output is correct
45 Correct 450 ms 57572 KB Output is correct
46 Correct 1489 ms 220212 KB Output is correct
47 Correct 1731 ms 234956 KB Output is correct
48 Correct 1772 ms 221256 KB Output is correct
49 Correct 1313 ms 221256 KB Output is correct
50 Correct 3107 ms 224712 KB Output is correct
51 Correct 2244 ms 223740 KB Output is correct
52 Correct 2630 ms 204628 KB Output is correct
53 Correct 2788 ms 193252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 325 ms 51680 KB Output is correct
2 Correct 288 ms 53856 KB Output is correct
3 Correct 256 ms 51556 KB Output is correct
4 Correct 322 ms 56676 KB Output is correct
5 Correct 16 ms 24044 KB Output is correct
6 Correct 296 ms 52324 KB Output is correct
7 Correct 163 ms 48484 KB Output is correct
8 Correct 115 ms 34156 KB Output is correct
9 Correct 264 ms 51556 KB Output is correct
10 Correct 256 ms 57696 KB Output is correct
11 Correct 208 ms 53092 KB Output is correct
12 Correct 16 ms 23916 KB Output is correct
13 Correct 16 ms 23916 KB Output is correct
14 Correct 16 ms 23916 KB Output is correct
15 Correct 16 ms 23916 KB Output is correct
16 Correct 16 ms 23916 KB Output is correct
17 Correct 16 ms 23916 KB Output is correct
18 Correct 16 ms 23916 KB Output is correct
19 Correct 16 ms 23916 KB Output is correct
20 Correct 16 ms 23916 KB Output is correct
21 Correct 16 ms 23916 KB Output is correct
22 Correct 16 ms 23916 KB Output is correct
23 Correct 17 ms 23916 KB Output is correct
24 Correct 16 ms 23916 KB Output is correct
25 Correct 16 ms 23916 KB Output is correct
26 Correct 17 ms 23916 KB Output is correct
27 Correct 16 ms 23916 KB Output is correct
28 Correct 19 ms 24300 KB Output is correct
29 Correct 19 ms 24172 KB Output is correct
30 Correct 20 ms 24300 KB Output is correct
31 Correct 19 ms 24300 KB Output is correct
32 Correct 19 ms 24172 KB Output is correct
33 Correct 19 ms 24172 KB Output is correct
34 Correct 19 ms 24172 KB Output is correct
35 Correct 258 ms 53972 KB Output is correct
36 Correct 337 ms 57956 KB Output is correct
37 Correct 268 ms 60756 KB Output is correct
38 Correct 314 ms 62688 KB Output is correct
39 Correct 320 ms 59356 KB Output is correct
40 Correct 240 ms 58724 KB Output is correct
41 Correct 480 ms 60764 KB Output is correct
42 Correct 172 ms 48108 KB Output is correct
43 Correct 98 ms 33772 KB Output is correct
44 Correct 378 ms 62044 KB Output is correct
45 Correct 413 ms 58844 KB Output is correct
46 Correct 423 ms 54236 KB Output is correct
47 Correct 434 ms 54368 KB Output is correct
48 Correct 299 ms 63700 KB Output is correct
49 Correct 328 ms 65760 KB Output is correct
50 Correct 340 ms 63072 KB Output is correct
51 Correct 271 ms 63328 KB Output is correct
52 Correct 16 ms 23916 KB Output is correct
53 Correct 510 ms 63944 KB Output is correct
54 Correct 404 ms 65008 KB Output is correct
55 Correct 435 ms 61680 KB Output is correct
56 Correct 450 ms 57572 KB Output is correct
57 Correct 348 ms 64212 KB Output is correct
58 Correct 292 ms 66208 KB Output is correct
59 Correct 277 ms 64096 KB Output is correct
60 Correct 350 ms 64096 KB Output is correct
61 Correct 692 ms 60764 KB Output is correct
62 Correct 17 ms 23916 KB Output is correct
63 Correct 513 ms 64108 KB Output is correct
64 Correct 400 ms 64348 KB Output is correct
65 Correct 430 ms 62428 KB Output is correct
66 Correct 467 ms 57692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 325 ms 51680 KB Output is correct
2 Correct 288 ms 53856 KB Output is correct
3 Correct 256 ms 51556 KB Output is correct
4 Correct 322 ms 56676 KB Output is correct
5 Correct 16 ms 24044 KB Output is correct
6 Correct 296 ms 52324 KB Output is correct
7 Correct 163 ms 48484 KB Output is correct
8 Correct 115 ms 34156 KB Output is correct
9 Correct 264 ms 51556 KB Output is correct
10 Correct 256 ms 57696 KB Output is correct
11 Correct 208 ms 53092 KB Output is correct
12 Correct 16 ms 23916 KB Output is correct
13 Correct 16 ms 23916 KB Output is correct
14 Correct 16 ms 23916 KB Output is correct
15 Correct 16 ms 23916 KB Output is correct
16 Correct 16 ms 23916 KB Output is correct
17 Correct 16 ms 23916 KB Output is correct
18 Correct 16 ms 23916 KB Output is correct
19 Correct 16 ms 23916 KB Output is correct
20 Correct 16 ms 23916 KB Output is correct
21 Correct 16 ms 23916 KB Output is correct
22 Correct 16 ms 23916 KB Output is correct
23 Correct 17 ms 23916 KB Output is correct
24 Correct 16 ms 23916 KB Output is correct
25 Correct 16 ms 23916 KB Output is correct
26 Correct 17 ms 23916 KB Output is correct
27 Correct 16 ms 23916 KB Output is correct
28 Correct 19 ms 24300 KB Output is correct
29 Correct 19 ms 24172 KB Output is correct
30 Correct 20 ms 24300 KB Output is correct
31 Correct 19 ms 24300 KB Output is correct
32 Correct 19 ms 24172 KB Output is correct
33 Correct 19 ms 24172 KB Output is correct
34 Correct 19 ms 24172 KB Output is correct
35 Correct 258 ms 53972 KB Output is correct
36 Correct 337 ms 57956 KB Output is correct
37 Correct 268 ms 60756 KB Output is correct
38 Correct 314 ms 62688 KB Output is correct
39 Correct 320 ms 59356 KB Output is correct
40 Correct 240 ms 58724 KB Output is correct
41 Correct 480 ms 60764 KB Output is correct
42 Correct 172 ms 48108 KB Output is correct
43 Correct 98 ms 33772 KB Output is correct
44 Correct 378 ms 62044 KB Output is correct
45 Correct 413 ms 58844 KB Output is correct
46 Correct 423 ms 54236 KB Output is correct
47 Correct 434 ms 54368 KB Output is correct
48 Correct 299 ms 63700 KB Output is correct
49 Correct 328 ms 65760 KB Output is correct
50 Correct 340 ms 63072 KB Output is correct
51 Correct 271 ms 63328 KB Output is correct
52 Correct 16 ms 23916 KB Output is correct
53 Correct 510 ms 63944 KB Output is correct
54 Correct 404 ms 65008 KB Output is correct
55 Correct 435 ms 61680 KB Output is correct
56 Correct 450 ms 57572 KB Output is correct
57 Correct 1489 ms 220212 KB Output is correct
58 Correct 1731 ms 234956 KB Output is correct
59 Correct 1772 ms 221256 KB Output is correct
60 Correct 1313 ms 221256 KB Output is correct
61 Correct 3107 ms 224712 KB Output is correct
62 Correct 2244 ms 223740 KB Output is correct
63 Correct 2630 ms 204628 KB Output is correct
64 Correct 2788 ms 193252 KB Output is correct
65 Correct 348 ms 64212 KB Output is correct
66 Correct 292 ms 66208 KB Output is correct
67 Correct 277 ms 64096 KB Output is correct
68 Correct 350 ms 64096 KB Output is correct
69 Correct 692 ms 60764 KB Output is correct
70 Correct 17 ms 23916 KB Output is correct
71 Correct 513 ms 64108 KB Output is correct
72 Correct 400 ms 64348 KB Output is correct
73 Correct 430 ms 62428 KB Output is correct
74 Correct 467 ms 57692 KB Output is correct
75 Correct 1793 ms 222056 KB Output is correct
76 Correct 1460 ms 236824 KB Output is correct
77 Correct 1339 ms 223816 KB Output is correct
78 Correct 1796 ms 223816 KB Output is correct
79 Correct 3204 ms 225352 KB Output is correct
80 Correct 2215 ms 220124 KB Output is correct
81 Correct 2475 ms 212804 KB Output is correct
82 Correct 2831 ms 193084 KB Output is correct
83 Correct 2950 ms 213184 KB Output is correct