Submission #532808

# Submission time Handle Problem Language Result Execution time Memory
532808 2022-03-04T01:20:05 Z 8e7 Two Dishes (JOI19_dishes) C++17
100 / 100
3223 ms 234488 KB
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 1000005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
struct obj{
	ll t, lim, val;
	obj(){t = lim = val = 0;}
	obj(ll x){t = x, lim = 0, val = 0;}
} a[maxn], b[maxn];
vector<int> upd[maxn];

const ll inf = 1LL<<60;

int main() {
	io
	int n, m;
	cin >> n >> m;
	for (int i = 1;i <= n;i++) {
		cin >> a[i].t >> a[i].lim >> a[i].val;	
		if (i) a[i].t += a[i-1].t;
	}
	for (int i = 0;i < m;i++) {
		cin >> b[i].t >> b[i].lim >> b[i].val;
		if (i) b[i].t += b[i-1].t;
	}
	for (int i = 1;i <= n;i++) {
		if (a[i].t > a[i].lim) {
			a[i].val = 0;
		} else {
			int ind = upper_bound(b, b + m, obj(a[i].lim - a[i].t), [&] (obj x, obj y){return x.t < y.t;}) - b;
			upd[ind].push_back(i);
		}
	}
	map<int, ll> mp; //difference array of g
	vector<int> neg;
	auto pref = [&] () {
		for (int p:neg) {
			if (mp[p] >= 0) continue;
			vector<int> val;
			auto it = mp.upper_bound(p);	
			ll x = -mp[p];
			mp[p] = 0;
			val.push_back(p);
			while (it != mp.end()) {
				if (it->ss > x) {
					it->ss -= x;
					break;
				} else {
					x -= it->ss;
					it->ss = 0;
					val.push_back(it->ff);
				}
				it = next(it);	
			}
			for (auto i:val) mp.erase(mp.find(i));
		}
		neg.clear();
	};
	auto ch = [&] (int p, ll x) {
		mp[p] += x;
		if (mp[p] < 0 && p) {
			neg.push_back(p);
		}
	};
	for (int i = 0;i < m;i++) {
		if (b[i].t <= b[i].lim) {
			int ind = upper_bound(a, a + n+1, obj(b[i].lim - b[i].t), [&] (obj x, obj y){return x.t < y.t;}) - a;
			ch(0, b[i].val);
			ch(ind, -b[i].val);
		}
		for (int j:upd[i]) {
			ch(j, a[j].val);
			a[j].val = 0;
		}
		sort(neg.begin(), neg.end(), [&] (int x, int y){return x > y;});
		neg.resize(int(unique(neg.begin(), neg.end()) - neg.begin()));
		pref();
		debug(i);
		for (auto j:mp) debug(j.ff, j.ss);
	}
	ll ans = 0;
	for (int i = 0;i <= n;i++) ans += a[i].val;
	for (auto i:mp) {
		if (i.ff <= n) ans += i.ss;
	}
	cout << ans << endl;
}
/*
5 3
2 5 1
4 6 1
1 8 1
2 13 1
1 14 1
1 3 1
2 3 1
3 12 1
*/

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:12:20: warning: statement has no effect [-Wunused-value]
   12 | #define debug(...) 0
      |                    ^
dishes.cpp:94:3: note: in expansion of macro 'debug'
   94 |   debug(i);
      |   ^~~~~
dishes.cpp:12:20: warning: statement has no effect [-Wunused-value]
   12 | #define debug(...) 0
      |                    ^
dishes.cpp:95:19: note: in expansion of macro 'debug'
   95 |   for (auto j:mp) debug(j.ff, j.ss);
      |                   ^~~~~
dishes.cpp:95:13: warning: variable 'j' set but not used [-Wunused-but-set-variable]
   95 |   for (auto j:mp) debug(j.ff, j.ss);
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 237 ms 74676 KB Output is correct
2 Correct 283 ms 83724 KB Output is correct
3 Correct 199 ms 72152 KB Output is correct
4 Correct 212 ms 74580 KB Output is correct
5 Correct 31 ms 70760 KB Output is correct
6 Correct 270 ms 87372 KB Output is correct
7 Correct 132 ms 77508 KB Output is correct
8 Correct 112 ms 78796 KB Output is correct
9 Correct 230 ms 86340 KB Output is correct
10 Correct 216 ms 84436 KB Output is correct
11 Correct 166 ms 79684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 70744 KB Output is correct
2 Correct 30 ms 70732 KB Output is correct
3 Correct 31 ms 70740 KB Output is correct
4 Correct 33 ms 70740 KB Output is correct
5 Correct 40 ms 70648 KB Output is correct
6 Correct 34 ms 70660 KB Output is correct
7 Correct 31 ms 70760 KB Output is correct
8 Correct 30 ms 70684 KB Output is correct
9 Correct 32 ms 70748 KB Output is correct
10 Correct 33 ms 70664 KB Output is correct
11 Correct 35 ms 70724 KB Output is correct
12 Correct 33 ms 70688 KB Output is correct
13 Correct 30 ms 70684 KB Output is correct
14 Correct 31 ms 70764 KB Output is correct
15 Correct 30 ms 70652 KB Output is correct
16 Correct 30 ms 70744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 70744 KB Output is correct
2 Correct 30 ms 70732 KB Output is correct
3 Correct 31 ms 70740 KB Output is correct
4 Correct 33 ms 70740 KB Output is correct
5 Correct 40 ms 70648 KB Output is correct
6 Correct 34 ms 70660 KB Output is correct
7 Correct 31 ms 70760 KB Output is correct
8 Correct 30 ms 70684 KB Output is correct
9 Correct 32 ms 70748 KB Output is correct
10 Correct 33 ms 70664 KB Output is correct
11 Correct 35 ms 70724 KB Output is correct
12 Correct 33 ms 70688 KB Output is correct
13 Correct 30 ms 70684 KB Output is correct
14 Correct 31 ms 70764 KB Output is correct
15 Correct 30 ms 70652 KB Output is correct
16 Correct 30 ms 70744 KB Output is correct
17 Correct 31 ms 70972 KB Output is correct
18 Correct 43 ms 70852 KB Output is correct
19 Correct 33 ms 70888 KB Output is correct
20 Correct 33 ms 70852 KB Output is correct
21 Correct 33 ms 70900 KB Output is correct
22 Correct 32 ms 70760 KB Output is correct
23 Correct 33 ms 70756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 70744 KB Output is correct
2 Correct 30 ms 70732 KB Output is correct
3 Correct 31 ms 70740 KB Output is correct
4 Correct 33 ms 70740 KB Output is correct
5 Correct 40 ms 70648 KB Output is correct
6 Correct 34 ms 70660 KB Output is correct
7 Correct 31 ms 70760 KB Output is correct
8 Correct 30 ms 70684 KB Output is correct
9 Correct 32 ms 70748 KB Output is correct
10 Correct 33 ms 70664 KB Output is correct
11 Correct 35 ms 70724 KB Output is correct
12 Correct 33 ms 70688 KB Output is correct
13 Correct 30 ms 70684 KB Output is correct
14 Correct 31 ms 70764 KB Output is correct
15 Correct 30 ms 70652 KB Output is correct
16 Correct 30 ms 70744 KB Output is correct
17 Correct 31 ms 70972 KB Output is correct
18 Correct 43 ms 70852 KB Output is correct
19 Correct 33 ms 70888 KB Output is correct
20 Correct 33 ms 70852 KB Output is correct
21 Correct 33 ms 70900 KB Output is correct
22 Correct 32 ms 70760 KB Output is correct
23 Correct 33 ms 70756 KB Output is correct
24 Correct 352 ms 94640 KB Output is correct
25 Correct 181 ms 81880 KB Output is correct
26 Correct 307 ms 100188 KB Output is correct
27 Correct 224 ms 82016 KB Output is correct
28 Correct 272 ms 83456 KB Output is correct
29 Correct 210 ms 83168 KB Output is correct
30 Correct 447 ms 85500 KB Output is correct
31 Correct 114 ms 75984 KB Output is correct
32 Correct 129 ms 83008 KB Output is correct
33 Correct 333 ms 83576 KB Output is correct
34 Correct 424 ms 88676 KB Output is correct
35 Correct 396 ms 79300 KB Output is correct
36 Correct 395 ms 78996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 70744 KB Output is correct
2 Correct 30 ms 70732 KB Output is correct
3 Correct 31 ms 70740 KB Output is correct
4 Correct 33 ms 70740 KB Output is correct
5 Correct 40 ms 70648 KB Output is correct
6 Correct 34 ms 70660 KB Output is correct
7 Correct 31 ms 70760 KB Output is correct
8 Correct 30 ms 70684 KB Output is correct
9 Correct 32 ms 70748 KB Output is correct
10 Correct 33 ms 70664 KB Output is correct
11 Correct 35 ms 70724 KB Output is correct
12 Correct 33 ms 70688 KB Output is correct
13 Correct 30 ms 70684 KB Output is correct
14 Correct 31 ms 70764 KB Output is correct
15 Correct 30 ms 70652 KB Output is correct
16 Correct 30 ms 70744 KB Output is correct
17 Correct 31 ms 70972 KB Output is correct
18 Correct 43 ms 70852 KB Output is correct
19 Correct 33 ms 70888 KB Output is correct
20 Correct 33 ms 70852 KB Output is correct
21 Correct 33 ms 70900 KB Output is correct
22 Correct 32 ms 70760 KB Output is correct
23 Correct 33 ms 70756 KB Output is correct
24 Correct 352 ms 94640 KB Output is correct
25 Correct 181 ms 81880 KB Output is correct
26 Correct 307 ms 100188 KB Output is correct
27 Correct 224 ms 82016 KB Output is correct
28 Correct 272 ms 83456 KB Output is correct
29 Correct 210 ms 83168 KB Output is correct
30 Correct 447 ms 85500 KB Output is correct
31 Correct 114 ms 75984 KB Output is correct
32 Correct 129 ms 83008 KB Output is correct
33 Correct 333 ms 83576 KB Output is correct
34 Correct 424 ms 88676 KB Output is correct
35 Correct 396 ms 79300 KB Output is correct
36 Correct 395 ms 78996 KB Output is correct
37 Correct 402 ms 103136 KB Output is correct
38 Correct 232 ms 85100 KB Output is correct
39 Correct 215 ms 88008 KB Output is correct
40 Correct 491 ms 101752 KB Output is correct
41 Correct 33 ms 70724 KB Output is correct
42 Correct 503 ms 88652 KB Output is correct
43 Correct 338 ms 86596 KB Output is correct
44 Correct 393 ms 91548 KB Output is correct
45 Correct 454 ms 82184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 70744 KB Output is correct
2 Correct 30 ms 70732 KB Output is correct
3 Correct 31 ms 70740 KB Output is correct
4 Correct 33 ms 70740 KB Output is correct
5 Correct 40 ms 70648 KB Output is correct
6 Correct 34 ms 70660 KB Output is correct
7 Correct 31 ms 70760 KB Output is correct
8 Correct 30 ms 70684 KB Output is correct
9 Correct 32 ms 70748 KB Output is correct
10 Correct 33 ms 70664 KB Output is correct
11 Correct 35 ms 70724 KB Output is correct
12 Correct 33 ms 70688 KB Output is correct
13 Correct 30 ms 70684 KB Output is correct
14 Correct 31 ms 70764 KB Output is correct
15 Correct 30 ms 70652 KB Output is correct
16 Correct 30 ms 70744 KB Output is correct
17 Correct 31 ms 70972 KB Output is correct
18 Correct 43 ms 70852 KB Output is correct
19 Correct 33 ms 70888 KB Output is correct
20 Correct 33 ms 70852 KB Output is correct
21 Correct 33 ms 70900 KB Output is correct
22 Correct 32 ms 70760 KB Output is correct
23 Correct 33 ms 70756 KB Output is correct
24 Correct 352 ms 94640 KB Output is correct
25 Correct 181 ms 81880 KB Output is correct
26 Correct 307 ms 100188 KB Output is correct
27 Correct 224 ms 82016 KB Output is correct
28 Correct 272 ms 83456 KB Output is correct
29 Correct 210 ms 83168 KB Output is correct
30 Correct 447 ms 85500 KB Output is correct
31 Correct 114 ms 75984 KB Output is correct
32 Correct 129 ms 83008 KB Output is correct
33 Correct 333 ms 83576 KB Output is correct
34 Correct 424 ms 88676 KB Output is correct
35 Correct 396 ms 79300 KB Output is correct
36 Correct 395 ms 78996 KB Output is correct
37 Correct 402 ms 103136 KB Output is correct
38 Correct 232 ms 85100 KB Output is correct
39 Correct 215 ms 88008 KB Output is correct
40 Correct 491 ms 101752 KB Output is correct
41 Correct 33 ms 70724 KB Output is correct
42 Correct 503 ms 88652 KB Output is correct
43 Correct 338 ms 86596 KB Output is correct
44 Correct 393 ms 91548 KB Output is correct
45 Correct 454 ms 82184 KB Output is correct
46 Correct 1668 ms 234488 KB Output is correct
47 Correct 945 ms 142820 KB Output is correct
48 Correct 1046 ms 158436 KB Output is correct
49 Correct 2157 ms 225088 KB Output is correct
50 Correct 3223 ms 161044 KB Output is correct
51 Correct 1946 ms 149796 KB Output is correct
52 Correct 2276 ms 168212 KB Output is correct
53 Correct 2653 ms 129360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 237 ms 74676 KB Output is correct
2 Correct 283 ms 83724 KB Output is correct
3 Correct 199 ms 72152 KB Output is correct
4 Correct 212 ms 74580 KB Output is correct
5 Correct 31 ms 70760 KB Output is correct
6 Correct 270 ms 87372 KB Output is correct
7 Correct 132 ms 77508 KB Output is correct
8 Correct 112 ms 78796 KB Output is correct
9 Correct 230 ms 86340 KB Output is correct
10 Correct 216 ms 84436 KB Output is correct
11 Correct 166 ms 79684 KB Output is correct
12 Correct 32 ms 70744 KB Output is correct
13 Correct 30 ms 70732 KB Output is correct
14 Correct 31 ms 70740 KB Output is correct
15 Correct 33 ms 70740 KB Output is correct
16 Correct 40 ms 70648 KB Output is correct
17 Correct 34 ms 70660 KB Output is correct
18 Correct 31 ms 70760 KB Output is correct
19 Correct 30 ms 70684 KB Output is correct
20 Correct 32 ms 70748 KB Output is correct
21 Correct 33 ms 70664 KB Output is correct
22 Correct 35 ms 70724 KB Output is correct
23 Correct 33 ms 70688 KB Output is correct
24 Correct 30 ms 70684 KB Output is correct
25 Correct 31 ms 70764 KB Output is correct
26 Correct 30 ms 70652 KB Output is correct
27 Correct 30 ms 70744 KB Output is correct
28 Correct 31 ms 70972 KB Output is correct
29 Correct 43 ms 70852 KB Output is correct
30 Correct 33 ms 70888 KB Output is correct
31 Correct 33 ms 70852 KB Output is correct
32 Correct 33 ms 70900 KB Output is correct
33 Correct 32 ms 70760 KB Output is correct
34 Correct 33 ms 70756 KB Output is correct
35 Correct 352 ms 94640 KB Output is correct
36 Correct 181 ms 81880 KB Output is correct
37 Correct 307 ms 100188 KB Output is correct
38 Correct 224 ms 82016 KB Output is correct
39 Correct 272 ms 83456 KB Output is correct
40 Correct 210 ms 83168 KB Output is correct
41 Correct 447 ms 85500 KB Output is correct
42 Correct 114 ms 75984 KB Output is correct
43 Correct 129 ms 83008 KB Output is correct
44 Correct 333 ms 83576 KB Output is correct
45 Correct 424 ms 88676 KB Output is correct
46 Correct 396 ms 79300 KB Output is correct
47 Correct 395 ms 78996 KB Output is correct
48 Correct 402 ms 103136 KB Output is correct
49 Correct 232 ms 85100 KB Output is correct
50 Correct 215 ms 88008 KB Output is correct
51 Correct 491 ms 101752 KB Output is correct
52 Correct 33 ms 70724 KB Output is correct
53 Correct 503 ms 88652 KB Output is correct
54 Correct 338 ms 86596 KB Output is correct
55 Correct 393 ms 91548 KB Output is correct
56 Correct 454 ms 82184 KB Output is correct
57 Correct 240 ms 91300 KB Output is correct
58 Correct 317 ms 97824 KB Output is correct
59 Correct 416 ms 102712 KB Output is correct
60 Correct 220 ms 88928 KB Output is correct
61 Correct 590 ms 98132 KB Output is correct
62 Correct 32 ms 70708 KB Output is correct
63 Correct 484 ms 88800 KB Output is correct
64 Correct 323 ms 86740 KB Output is correct
65 Correct 405 ms 88416 KB Output is correct
66 Correct 449 ms 82260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 237 ms 74676 KB Output is correct
2 Correct 283 ms 83724 KB Output is correct
3 Correct 199 ms 72152 KB Output is correct
4 Correct 212 ms 74580 KB Output is correct
5 Correct 31 ms 70760 KB Output is correct
6 Correct 270 ms 87372 KB Output is correct
7 Correct 132 ms 77508 KB Output is correct
8 Correct 112 ms 78796 KB Output is correct
9 Correct 230 ms 86340 KB Output is correct
10 Correct 216 ms 84436 KB Output is correct
11 Correct 166 ms 79684 KB Output is correct
12 Correct 32 ms 70744 KB Output is correct
13 Correct 30 ms 70732 KB Output is correct
14 Correct 31 ms 70740 KB Output is correct
15 Correct 33 ms 70740 KB Output is correct
16 Correct 40 ms 70648 KB Output is correct
17 Correct 34 ms 70660 KB Output is correct
18 Correct 31 ms 70760 KB Output is correct
19 Correct 30 ms 70684 KB Output is correct
20 Correct 32 ms 70748 KB Output is correct
21 Correct 33 ms 70664 KB Output is correct
22 Correct 35 ms 70724 KB Output is correct
23 Correct 33 ms 70688 KB Output is correct
24 Correct 30 ms 70684 KB Output is correct
25 Correct 31 ms 70764 KB Output is correct
26 Correct 30 ms 70652 KB Output is correct
27 Correct 30 ms 70744 KB Output is correct
28 Correct 31 ms 70972 KB Output is correct
29 Correct 43 ms 70852 KB Output is correct
30 Correct 33 ms 70888 KB Output is correct
31 Correct 33 ms 70852 KB Output is correct
32 Correct 33 ms 70900 KB Output is correct
33 Correct 32 ms 70760 KB Output is correct
34 Correct 33 ms 70756 KB Output is correct
35 Correct 352 ms 94640 KB Output is correct
36 Correct 181 ms 81880 KB Output is correct
37 Correct 307 ms 100188 KB Output is correct
38 Correct 224 ms 82016 KB Output is correct
39 Correct 272 ms 83456 KB Output is correct
40 Correct 210 ms 83168 KB Output is correct
41 Correct 447 ms 85500 KB Output is correct
42 Correct 114 ms 75984 KB Output is correct
43 Correct 129 ms 83008 KB Output is correct
44 Correct 333 ms 83576 KB Output is correct
45 Correct 424 ms 88676 KB Output is correct
46 Correct 396 ms 79300 KB Output is correct
47 Correct 395 ms 78996 KB Output is correct
48 Correct 402 ms 103136 KB Output is correct
49 Correct 232 ms 85100 KB Output is correct
50 Correct 215 ms 88008 KB Output is correct
51 Correct 491 ms 101752 KB Output is correct
52 Correct 33 ms 70724 KB Output is correct
53 Correct 503 ms 88652 KB Output is correct
54 Correct 338 ms 86596 KB Output is correct
55 Correct 393 ms 91548 KB Output is correct
56 Correct 454 ms 82184 KB Output is correct
57 Correct 1668 ms 234488 KB Output is correct
58 Correct 945 ms 142820 KB Output is correct
59 Correct 1046 ms 158436 KB Output is correct
60 Correct 2157 ms 225088 KB Output is correct
61 Correct 3223 ms 161044 KB Output is correct
62 Correct 1946 ms 149796 KB Output is correct
63 Correct 2276 ms 168212 KB Output is correct
64 Correct 2653 ms 129360 KB Output is correct
65 Correct 240 ms 91300 KB Output is correct
66 Correct 317 ms 97824 KB Output is correct
67 Correct 416 ms 102712 KB Output is correct
68 Correct 220 ms 88928 KB Output is correct
69 Correct 590 ms 98132 KB Output is correct
70 Correct 32 ms 70708 KB Output is correct
71 Correct 484 ms 88800 KB Output is correct
72 Correct 323 ms 86740 KB Output is correct
73 Correct 405 ms 88416 KB Output is correct
74 Correct 449 ms 82260 KB Output is correct
75 Correct 1074 ms 173132 KB Output is correct
76 Correct 1476 ms 205548 KB Output is correct
77 Correct 1961 ms 226908 KB Output is correct
78 Correct 949 ms 160920 KB Output is correct
79 Correct 3027 ms 160404 KB Output is correct
80 Correct 1799 ms 149640 KB Output is correct
81 Correct 2322 ms 158564 KB Output is correct
82 Correct 2734 ms 128760 KB Output is correct
83 Correct 2767 ms 148312 KB Output is correct