답안 #260183

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
260183 2020-08-09T14:11:49 Z mjkocijan Two Dishes (JOI19_dishes) C++14
100 / 100
7409 ms 218744 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;
#define X first
#define Y second
#define pb push_back
typedef long double ld;
#define MAXN 1001001
#define INF 1001001001001001001LL

int n, m, nn = 1 << 20;
ll a[MAXN], s[MAXN], p[MAXN];
ll b[MAXN], u[MAXN], k[MAXN];
vector<ii> x[MAXN];
ll ap[MAXN], bp[MAXN];
ll t[4 * MAXN];
ll pd[4 * MAXN], pm[4 * MAXN];

void propaj(int cv)
{
	//if (cv >= nn) cout << " (" << cv - nn << ' ' << t[cv] << ' '<< pd[cv] << ' ' << (pm[cv] < -INF / 2 ? -9 : pm[cv])<<") ";
	t[cv] += pd[cv];
	t[cv] = max(t[cv], pm[cv]);
	if (cv < nn) {
		pd[cv * 2] += pd[cv];
		pd[cv * 2 + 1] += pd[cv];
		pm[cv * 2] += pd[cv];
		pm[cv * 2 + 1] += pd[cv];
		pm[cv * 2] = max(pm[cv * 2], pm[cv]);
		pm[cv * 2 + 1] = max(pm[cv * 2 + 1], pm[cv]);
	}
	pd[cv] = 0;
	pm[cv] = -INF;
}

void dodaj(int cv, int lo, int hi, int l, int r, ll h)
{
	propaj(cv);//cout<<cv<<' '<<lo<<' '<<hi<<' '<<l<<' '<<r<<' '<<h<<endl;

  if (lo > hi || lo > r || hi < l || l > r) return;//cout<<"ok!\n";
  
  if (lo >= l && hi <= r) {//cout<<'.'<<lo<<'.'<<hi<<'.'<<h<<endl;
  	pd[cv] += h;
  	pm[cv] += h;
  	return;
  }
  
  int mid = (lo + hi) / 2;
  
  dodaj(cv * 2, lo, mid, l, r, h);
  dodaj(cv * 2 + 1, mid + 1, hi, l, r, h);
}

void maxaj(int cv, int lo, int hi, int l, int r, ll h)
{
	propaj(cv);

  if (lo > hi || lo > r || hi < l || l > r) return;
  
  if (lo >= l && hi <= r) {
  	pm[cv] = max(pm[cv], h);
  	return;
  }
  
  int mid = (lo + hi) / 2;
  
  maxaj(cv * 2, lo, mid, l, r, h);
  maxaj(cv * 2 + 1, mid + 1, hi, l, r, h);
}

ll kveri(int cv, int lo, int hi, int h)
{
	propaj(cv);
	
	if (lo == hi) {
		return t[cv];
	}
	
	int mid = (lo + hi) / 2;
	
	if (h <= mid)
		return kveri(cv * 2, lo, mid, h);
	else
		return kveri(cv * 2 + 1, mid + 1, hi, h);
}

ll reza = 0LL, r[MAXN], r2[MAXN];

int main()
{
	for (int i = 0; i < 4 * MAXN; i++)
		pm[i] = -INF;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
  	scanf("%lld%lld%lld", &a[i], &s[i], &p[i]);
  	ap[i + 1] = a[i] + (i ? ap[i] : 0);
  }
  for (int i = 0; i < m; i++) {
  	scanf("%lld%lld%lld", &b[i], &u[i], &k[i]);
  	bp[i + 1] = b[i] + (i ? bp[i] : 0);
  }
  for (int i = 0; i < n; i++) {
  	x[i].pb({upper_bound(bp, bp + m + 1, (s[i] - ap[i + 1])) - bp, p[i]});
  }
  for (int i = 0; i < m; i++) {
  	ll izraz = upper_bound(ap, ap + n + 1, (u[i] - bp[i + 1])) - ap - 1;
  	if (izraz == n)
  		reza += k[i];
  	else if (izraz >= 0) {
  		x[izraz].pb({i + 1, -k[i]});
  	reza += k[i];//cout<<izraz<<".,..";
  	//r2[i + 1] += k[i];
  	}
  }
  //for (int i = 0; i <= m; i++) r[i] = r2[i] + (i ? r[i - 1] : 0);
  for (int i = 0; i <= n; i++) {
  	//cout << i << ": ";
  	for (ii j: x[i]) {
  		//cout << j.X <<' '<<j.Y<<", ";
  		dodaj(1, 0, nn - 1, 0, j.X - 1, j.Y);//for (int j = 0; j <= m; j++) cout << kveri(1, 0, nn - 1, j) << ' '; cout << endl;
  	}//cout << endl;
  	for (ii j: x[i]) {
  		//if (j.X)
  			maxaj(1, 0, nn - 1, j.X, m, kveri(1, 0, nn - 1, j.X - 1));//for (int j = 0; j <= m; j++) cout << kveri(1, 0, nn - 1, j) << ' '; cout << endl;
  	}
  	//for (int j = 0; j <= m; j++) cout << kveri(1, 0, nn - 1, j) << ' '; cout << endl;
  }//cout<<reza<<endl;
  printf("%lld\n", reza + kveri(1, 0, nn - 1, m));
  return 0;
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:94:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &n, &m);
   ~~~~~^~~~~~~~~~~~~~~~
dishes.cpp:96:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld%lld%lld", &a[i], &s[i], &p[i]);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:100:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld%lld%lld", &b[i], &u[i], &k[i]);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 779 ms 92668 KB Output is correct
2 Correct 745 ms 91604 KB Output is correct
3 Correct 368 ms 81912 KB Output is correct
4 Correct 642 ms 87928 KB Output is correct
5 Correct 36 ms 55416 KB Output is correct
6 Correct 681 ms 89116 KB Output is correct
7 Correct 142 ms 68472 KB Output is correct
8 Correct 302 ms 75044 KB Output is correct
9 Correct 387 ms 83576 KB Output is correct
10 Correct 744 ms 91000 KB Output is correct
11 Correct 310 ms 81896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 55416 KB Output is correct
2 Correct 33 ms 55424 KB Output is correct
3 Correct 32 ms 55424 KB Output is correct
4 Correct 32 ms 55424 KB Output is correct
5 Correct 33 ms 55416 KB Output is correct
6 Correct 32 ms 55416 KB Output is correct
7 Correct 33 ms 55424 KB Output is correct
8 Correct 32 ms 55416 KB Output is correct
9 Correct 32 ms 55416 KB Output is correct
10 Correct 32 ms 55416 KB Output is correct
11 Correct 32 ms 55420 KB Output is correct
12 Correct 32 ms 55416 KB Output is correct
13 Correct 32 ms 55424 KB Output is correct
14 Correct 35 ms 55420 KB Output is correct
15 Correct 33 ms 55424 KB Output is correct
16 Correct 33 ms 55420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 55416 KB Output is correct
2 Correct 33 ms 55424 KB Output is correct
3 Correct 32 ms 55424 KB Output is correct
4 Correct 32 ms 55424 KB Output is correct
5 Correct 33 ms 55416 KB Output is correct
6 Correct 32 ms 55416 KB Output is correct
7 Correct 33 ms 55424 KB Output is correct
8 Correct 32 ms 55416 KB Output is correct
9 Correct 32 ms 55416 KB Output is correct
10 Correct 32 ms 55416 KB Output is correct
11 Correct 32 ms 55420 KB Output is correct
12 Correct 32 ms 55416 KB Output is correct
13 Correct 32 ms 55424 KB Output is correct
14 Correct 35 ms 55420 KB Output is correct
15 Correct 33 ms 55424 KB Output is correct
16 Correct 33 ms 55420 KB Output is correct
17 Correct 43 ms 55676 KB Output is correct
18 Correct 36 ms 55808 KB Output is correct
19 Correct 37 ms 55800 KB Output is correct
20 Correct 47 ms 55808 KB Output is correct
21 Correct 36 ms 55800 KB Output is correct
22 Correct 47 ms 55672 KB Output is correct
23 Correct 39 ms 55672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 55416 KB Output is correct
2 Correct 33 ms 55424 KB Output is correct
3 Correct 32 ms 55424 KB Output is correct
4 Correct 32 ms 55424 KB Output is correct
5 Correct 33 ms 55416 KB Output is correct
6 Correct 32 ms 55416 KB Output is correct
7 Correct 33 ms 55424 KB Output is correct
8 Correct 32 ms 55416 KB Output is correct
9 Correct 32 ms 55416 KB Output is correct
10 Correct 32 ms 55416 KB Output is correct
11 Correct 32 ms 55420 KB Output is correct
12 Correct 32 ms 55416 KB Output is correct
13 Correct 32 ms 55424 KB Output is correct
14 Correct 35 ms 55420 KB Output is correct
15 Correct 33 ms 55424 KB Output is correct
16 Correct 33 ms 55420 KB Output is correct
17 Correct 43 ms 55676 KB Output is correct
18 Correct 36 ms 55808 KB Output is correct
19 Correct 37 ms 55800 KB Output is correct
20 Correct 47 ms 55808 KB Output is correct
21 Correct 36 ms 55800 KB Output is correct
22 Correct 47 ms 55672 KB Output is correct
23 Correct 39 ms 55672 KB Output is correct
24 Correct 565 ms 84504 KB Output is correct
25 Correct 597 ms 93788 KB Output is correct
26 Correct 511 ms 90360 KB Output is correct
27 Correct 656 ms 93176 KB Output is correct
28 Correct 616 ms 91764 KB Output is correct
29 Correct 354 ms 82872 KB Output is correct
30 Correct 1131 ms 95316 KB Output is correct
31 Correct 270 ms 74852 KB Output is correct
32 Correct 321 ms 73240 KB Output is correct
33 Correct 736 ms 92792 KB Output is correct
34 Correct 929 ms 93688 KB Output is correct
35 Correct 1028 ms 90360 KB Output is correct
36 Correct 1016 ms 90128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 55416 KB Output is correct
2 Correct 33 ms 55424 KB Output is correct
3 Correct 32 ms 55424 KB Output is correct
4 Correct 32 ms 55424 KB Output is correct
5 Correct 33 ms 55416 KB Output is correct
6 Correct 32 ms 55416 KB Output is correct
7 Correct 33 ms 55424 KB Output is correct
8 Correct 32 ms 55416 KB Output is correct
9 Correct 32 ms 55416 KB Output is correct
10 Correct 32 ms 55416 KB Output is correct
11 Correct 32 ms 55420 KB Output is correct
12 Correct 32 ms 55416 KB Output is correct
13 Correct 32 ms 55424 KB Output is correct
14 Correct 35 ms 55420 KB Output is correct
15 Correct 33 ms 55424 KB Output is correct
16 Correct 33 ms 55420 KB Output is correct
17 Correct 43 ms 55676 KB Output is correct
18 Correct 36 ms 55808 KB Output is correct
19 Correct 37 ms 55800 KB Output is correct
20 Correct 47 ms 55808 KB Output is correct
21 Correct 36 ms 55800 KB Output is correct
22 Correct 47 ms 55672 KB Output is correct
23 Correct 39 ms 55672 KB Output is correct
24 Correct 565 ms 84504 KB Output is correct
25 Correct 597 ms 93788 KB Output is correct
26 Correct 511 ms 90360 KB Output is correct
27 Correct 656 ms 93176 KB Output is correct
28 Correct 616 ms 91764 KB Output is correct
29 Correct 354 ms 82872 KB Output is correct
30 Correct 1131 ms 95316 KB Output is correct
31 Correct 270 ms 74852 KB Output is correct
32 Correct 321 ms 73240 KB Output is correct
33 Correct 736 ms 92792 KB Output is correct
34 Correct 929 ms 93688 KB Output is correct
35 Correct 1028 ms 90360 KB Output is correct
36 Correct 1016 ms 90128 KB Output is correct
37 Correct 611 ms 87444 KB Output is correct
38 Correct 707 ms 90232 KB Output is correct
39 Correct 800 ms 92280 KB Output is correct
40 Correct 793 ms 92024 KB Output is correct
41 Correct 33 ms 55416 KB Output is correct
42 Correct 1111 ms 92060 KB Output is correct
43 Correct 785 ms 89388 KB Output is correct
44 Correct 952 ms 90172 KB Output is correct
45 Correct 1097 ms 93316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 55416 KB Output is correct
2 Correct 33 ms 55424 KB Output is correct
3 Correct 32 ms 55424 KB Output is correct
4 Correct 32 ms 55424 KB Output is correct
5 Correct 33 ms 55416 KB Output is correct
6 Correct 32 ms 55416 KB Output is correct
7 Correct 33 ms 55424 KB Output is correct
8 Correct 32 ms 55416 KB Output is correct
9 Correct 32 ms 55416 KB Output is correct
10 Correct 32 ms 55416 KB Output is correct
11 Correct 32 ms 55420 KB Output is correct
12 Correct 32 ms 55416 KB Output is correct
13 Correct 32 ms 55424 KB Output is correct
14 Correct 35 ms 55420 KB Output is correct
15 Correct 33 ms 55424 KB Output is correct
16 Correct 33 ms 55420 KB Output is correct
17 Correct 43 ms 55676 KB Output is correct
18 Correct 36 ms 55808 KB Output is correct
19 Correct 37 ms 55800 KB Output is correct
20 Correct 47 ms 55808 KB Output is correct
21 Correct 36 ms 55800 KB Output is correct
22 Correct 47 ms 55672 KB Output is correct
23 Correct 39 ms 55672 KB Output is correct
24 Correct 565 ms 84504 KB Output is correct
25 Correct 597 ms 93788 KB Output is correct
26 Correct 511 ms 90360 KB Output is correct
27 Correct 656 ms 93176 KB Output is correct
28 Correct 616 ms 91764 KB Output is correct
29 Correct 354 ms 82872 KB Output is correct
30 Correct 1131 ms 95316 KB Output is correct
31 Correct 270 ms 74852 KB Output is correct
32 Correct 321 ms 73240 KB Output is correct
33 Correct 736 ms 92792 KB Output is correct
34 Correct 929 ms 93688 KB Output is correct
35 Correct 1028 ms 90360 KB Output is correct
36 Correct 1016 ms 90128 KB Output is correct
37 Correct 611 ms 87444 KB Output is correct
38 Correct 707 ms 90232 KB Output is correct
39 Correct 800 ms 92280 KB Output is correct
40 Correct 793 ms 92024 KB Output is correct
41 Correct 33 ms 55416 KB Output is correct
42 Correct 1111 ms 92060 KB Output is correct
43 Correct 785 ms 89388 KB Output is correct
44 Correct 952 ms 90172 KB Output is correct
45 Correct 1097 ms 93316 KB Output is correct
46 Correct 2705 ms 191984 KB Output is correct
47 Correct 3388 ms 204840 KB Output is correct
48 Correct 3911 ms 203356 KB Output is correct
49 Correct 3981 ms 203356 KB Output is correct
50 Correct 7409 ms 216680 KB Output is correct
51 Correct 4144 ms 199800 KB Output is correct
52 Correct 5156 ms 201104 KB Output is correct
53 Correct 6879 ms 212020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 779 ms 92668 KB Output is correct
2 Correct 745 ms 91604 KB Output is correct
3 Correct 368 ms 81912 KB Output is correct
4 Correct 642 ms 87928 KB Output is correct
5 Correct 36 ms 55416 KB Output is correct
6 Correct 681 ms 89116 KB Output is correct
7 Correct 142 ms 68472 KB Output is correct
8 Correct 302 ms 75044 KB Output is correct
9 Correct 387 ms 83576 KB Output is correct
10 Correct 744 ms 91000 KB Output is correct
11 Correct 310 ms 81896 KB Output is correct
12 Correct 32 ms 55416 KB Output is correct
13 Correct 33 ms 55424 KB Output is correct
14 Correct 32 ms 55424 KB Output is correct
15 Correct 32 ms 55424 KB Output is correct
16 Correct 33 ms 55416 KB Output is correct
17 Correct 32 ms 55416 KB Output is correct
18 Correct 33 ms 55424 KB Output is correct
19 Correct 32 ms 55416 KB Output is correct
20 Correct 32 ms 55416 KB Output is correct
21 Correct 32 ms 55416 KB Output is correct
22 Correct 32 ms 55420 KB Output is correct
23 Correct 32 ms 55416 KB Output is correct
24 Correct 32 ms 55424 KB Output is correct
25 Correct 35 ms 55420 KB Output is correct
26 Correct 33 ms 55424 KB Output is correct
27 Correct 33 ms 55420 KB Output is correct
28 Correct 43 ms 55676 KB Output is correct
29 Correct 36 ms 55808 KB Output is correct
30 Correct 37 ms 55800 KB Output is correct
31 Correct 47 ms 55808 KB Output is correct
32 Correct 36 ms 55800 KB Output is correct
33 Correct 47 ms 55672 KB Output is correct
34 Correct 39 ms 55672 KB Output is correct
35 Correct 565 ms 84504 KB Output is correct
36 Correct 597 ms 93788 KB Output is correct
37 Correct 511 ms 90360 KB Output is correct
38 Correct 656 ms 93176 KB Output is correct
39 Correct 616 ms 91764 KB Output is correct
40 Correct 354 ms 82872 KB Output is correct
41 Correct 1131 ms 95316 KB Output is correct
42 Correct 270 ms 74852 KB Output is correct
43 Correct 321 ms 73240 KB Output is correct
44 Correct 736 ms 92792 KB Output is correct
45 Correct 929 ms 93688 KB Output is correct
46 Correct 1028 ms 90360 KB Output is correct
47 Correct 1016 ms 90128 KB Output is correct
48 Correct 611 ms 87444 KB Output is correct
49 Correct 707 ms 90232 KB Output is correct
50 Correct 800 ms 92280 KB Output is correct
51 Correct 793 ms 92024 KB Output is correct
52 Correct 33 ms 55416 KB Output is correct
53 Correct 1111 ms 92060 KB Output is correct
54 Correct 785 ms 89388 KB Output is correct
55 Correct 952 ms 90172 KB Output is correct
56 Correct 1097 ms 93316 KB Output is correct
57 Correct 570 ms 89080 KB Output is correct
58 Correct 718 ms 97732 KB Output is correct
59 Correct 812 ms 95736 KB Output is correct
60 Correct 806 ms 95608 KB Output is correct
61 Correct 1184 ms 96768 KB Output is correct
62 Correct 41 ms 55416 KB Output is correct
63 Correct 1195 ms 99832 KB Output is correct
64 Correct 760 ms 96632 KB Output is correct
65 Correct 924 ms 97400 KB Output is correct
66 Correct 1117 ms 93560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 779 ms 92668 KB Output is correct
2 Correct 745 ms 91604 KB Output is correct
3 Correct 368 ms 81912 KB Output is correct
4 Correct 642 ms 87928 KB Output is correct
5 Correct 36 ms 55416 KB Output is correct
6 Correct 681 ms 89116 KB Output is correct
7 Correct 142 ms 68472 KB Output is correct
8 Correct 302 ms 75044 KB Output is correct
9 Correct 387 ms 83576 KB Output is correct
10 Correct 744 ms 91000 KB Output is correct
11 Correct 310 ms 81896 KB Output is correct
12 Correct 32 ms 55416 KB Output is correct
13 Correct 33 ms 55424 KB Output is correct
14 Correct 32 ms 55424 KB Output is correct
15 Correct 32 ms 55424 KB Output is correct
16 Correct 33 ms 55416 KB Output is correct
17 Correct 32 ms 55416 KB Output is correct
18 Correct 33 ms 55424 KB Output is correct
19 Correct 32 ms 55416 KB Output is correct
20 Correct 32 ms 55416 KB Output is correct
21 Correct 32 ms 55416 KB Output is correct
22 Correct 32 ms 55420 KB Output is correct
23 Correct 32 ms 55416 KB Output is correct
24 Correct 32 ms 55424 KB Output is correct
25 Correct 35 ms 55420 KB Output is correct
26 Correct 33 ms 55424 KB Output is correct
27 Correct 33 ms 55420 KB Output is correct
28 Correct 43 ms 55676 KB Output is correct
29 Correct 36 ms 55808 KB Output is correct
30 Correct 37 ms 55800 KB Output is correct
31 Correct 47 ms 55808 KB Output is correct
32 Correct 36 ms 55800 KB Output is correct
33 Correct 47 ms 55672 KB Output is correct
34 Correct 39 ms 55672 KB Output is correct
35 Correct 565 ms 84504 KB Output is correct
36 Correct 597 ms 93788 KB Output is correct
37 Correct 511 ms 90360 KB Output is correct
38 Correct 656 ms 93176 KB Output is correct
39 Correct 616 ms 91764 KB Output is correct
40 Correct 354 ms 82872 KB Output is correct
41 Correct 1131 ms 95316 KB Output is correct
42 Correct 270 ms 74852 KB Output is correct
43 Correct 321 ms 73240 KB Output is correct
44 Correct 736 ms 92792 KB Output is correct
45 Correct 929 ms 93688 KB Output is correct
46 Correct 1028 ms 90360 KB Output is correct
47 Correct 1016 ms 90128 KB Output is correct
48 Correct 611 ms 87444 KB Output is correct
49 Correct 707 ms 90232 KB Output is correct
50 Correct 800 ms 92280 KB Output is correct
51 Correct 793 ms 92024 KB Output is correct
52 Correct 33 ms 55416 KB Output is correct
53 Correct 1111 ms 92060 KB Output is correct
54 Correct 785 ms 89388 KB Output is correct
55 Correct 952 ms 90172 KB Output is correct
56 Correct 1097 ms 93316 KB Output is correct
57 Correct 2705 ms 191984 KB Output is correct
58 Correct 3388 ms 204840 KB Output is correct
59 Correct 3911 ms 203356 KB Output is correct
60 Correct 3981 ms 203356 KB Output is correct
61 Correct 7409 ms 216680 KB Output is correct
62 Correct 4144 ms 199800 KB Output is correct
63 Correct 5156 ms 201104 KB Output is correct
64 Correct 6879 ms 212020 KB Output is correct
65 Correct 570 ms 89080 KB Output is correct
66 Correct 718 ms 97732 KB Output is correct
67 Correct 812 ms 95736 KB Output is correct
68 Correct 806 ms 95608 KB Output is correct
69 Correct 1184 ms 96768 KB Output is correct
70 Correct 41 ms 55416 KB Output is correct
71 Correct 1195 ms 99832 KB Output is correct
72 Correct 760 ms 96632 KB Output is correct
73 Correct 924 ms 97400 KB Output is correct
74 Correct 1117 ms 93560 KB Output is correct
75 Correct 2741 ms 191628 KB Output is correct
76 Correct 3472 ms 207092 KB Output is correct
77 Correct 3975 ms 205584 KB Output is correct
78 Correct 3986 ms 205588 KB Output is correct
79 Correct 6978 ms 218744 KB Output is correct
80 Correct 4341 ms 201848 KB Output is correct
81 Correct 4980 ms 201088 KB Output is correct
82 Correct 6583 ms 213624 KB Output is correct
83 Correct 6455 ms 215216 KB Output is correct