답안 #260170

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
260170 2020-08-09T13:17:32 Z mjkocijan Two Dishes (JOI19_dishes) C++14
74 / 100
6997 ms 215340 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;

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 >= 0) {
  		x[izraz].pb({i + 1, -k[i]});
  	reza += k[i];//cout<<izraz<<".,..";
  	}
  }
  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 798 ms 95152 KB Output is correct
2 Correct 795 ms 96976 KB Output is correct
3 Correct 651 ms 96092 KB Output is correct
4 Correct 642 ms 92280 KB Output is correct
5 Correct 32 ms 55424 KB Output is correct
6 Correct 744 ms 96032 KB Output is correct
7 Correct 383 ms 77020 KB Output is correct
8 Correct 277 ms 75000 KB Output is correct
9 Correct 672 ms 95788 KB Output is correct
10 Correct 747 ms 90908 KB Output is correct
11 Correct 599 ms 91612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 55416 KB Output is correct
2 Correct 40 ms 55416 KB Output is correct
3 Correct 38 ms 55416 KB Output is correct
4 Correct 32 ms 55416 KB Output is correct
5 Correct 32 ms 55416 KB Output is correct
6 Correct 31 ms 55416 KB Output is correct
7 Correct 33 ms 55416 KB Output is correct
8 Correct 32 ms 55424 KB Output is correct
9 Correct 36 ms 55416 KB Output is correct
10 Correct 32 ms 55416 KB Output is correct
11 Correct 32 ms 55416 KB Output is correct
12 Correct 31 ms 55424 KB Output is correct
13 Correct 35 ms 55424 KB Output is correct
14 Correct 32 ms 55424 KB Output is correct
15 Correct 36 ms 55416 KB Output is correct
16 Correct 32 ms 55416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 55416 KB Output is correct
2 Correct 40 ms 55416 KB Output is correct
3 Correct 38 ms 55416 KB Output is correct
4 Correct 32 ms 55416 KB Output is correct
5 Correct 32 ms 55416 KB Output is correct
6 Correct 31 ms 55416 KB Output is correct
7 Correct 33 ms 55416 KB Output is correct
8 Correct 32 ms 55424 KB Output is correct
9 Correct 36 ms 55416 KB Output is correct
10 Correct 32 ms 55416 KB Output is correct
11 Correct 32 ms 55416 KB Output is correct
12 Correct 31 ms 55424 KB Output is correct
13 Correct 35 ms 55424 KB Output is correct
14 Correct 32 ms 55424 KB Output is correct
15 Correct 36 ms 55416 KB Output is correct
16 Correct 32 ms 55416 KB Output is correct
17 Correct 37 ms 55672 KB Output is correct
18 Correct 39 ms 55800 KB Output is correct
19 Correct 40 ms 55800 KB Output is correct
20 Correct 39 ms 55932 KB Output is correct
21 Correct 39 ms 55808 KB Output is correct
22 Correct 39 ms 55680 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 40 ms 55416 KB Output is correct
3 Correct 38 ms 55416 KB Output is correct
4 Correct 32 ms 55416 KB Output is correct
5 Correct 32 ms 55416 KB Output is correct
6 Correct 31 ms 55416 KB Output is correct
7 Correct 33 ms 55416 KB Output is correct
8 Correct 32 ms 55424 KB Output is correct
9 Correct 36 ms 55416 KB Output is correct
10 Correct 32 ms 55416 KB Output is correct
11 Correct 32 ms 55416 KB Output is correct
12 Correct 31 ms 55424 KB Output is correct
13 Correct 35 ms 55424 KB Output is correct
14 Correct 32 ms 55424 KB Output is correct
15 Correct 36 ms 55416 KB Output is correct
16 Correct 32 ms 55416 KB Output is correct
17 Correct 37 ms 55672 KB Output is correct
18 Correct 39 ms 55800 KB Output is correct
19 Correct 40 ms 55800 KB Output is correct
20 Correct 39 ms 55932 KB Output is correct
21 Correct 39 ms 55808 KB Output is correct
22 Correct 39 ms 55680 KB Output is correct
23 Correct 39 ms 55672 KB Output is correct
24 Correct 686 ms 92648 KB Output is correct
25 Correct 595 ms 94248 KB Output is correct
26 Correct 622 ms 92772 KB Output is correct
27 Correct 667 ms 94200 KB Output is correct
28 Correct 738 ms 95076 KB Output is correct
29 Correct 617 ms 94940 KB Output is correct
30 Correct 1116 ms 96760 KB Output is correct
31 Correct 417 ms 76376 KB Output is correct
32 Correct 316 ms 73080 KB Output is correct
33 Correct 869 ms 93816 KB Output is correct
34 Correct 1022 ms 95212 KB Output is correct
35 Correct 1036 ms 90232 KB Output is correct
36 Correct 1020 ms 90124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 55416 KB Output is correct
2 Correct 40 ms 55416 KB Output is correct
3 Correct 38 ms 55416 KB Output is correct
4 Correct 32 ms 55416 KB Output is correct
5 Correct 32 ms 55416 KB Output is correct
6 Correct 31 ms 55416 KB Output is correct
7 Correct 33 ms 55416 KB Output is correct
8 Correct 32 ms 55424 KB Output is correct
9 Correct 36 ms 55416 KB Output is correct
10 Correct 32 ms 55416 KB Output is correct
11 Correct 32 ms 55416 KB Output is correct
12 Correct 31 ms 55424 KB Output is correct
13 Correct 35 ms 55424 KB Output is correct
14 Correct 32 ms 55424 KB Output is correct
15 Correct 36 ms 55416 KB Output is correct
16 Correct 32 ms 55416 KB Output is correct
17 Correct 37 ms 55672 KB Output is correct
18 Correct 39 ms 55800 KB Output is correct
19 Correct 40 ms 55800 KB Output is correct
20 Correct 39 ms 55932 KB Output is correct
21 Correct 39 ms 55808 KB Output is correct
22 Correct 39 ms 55680 KB Output is correct
23 Correct 39 ms 55672 KB Output is correct
24 Correct 686 ms 92648 KB Output is correct
25 Correct 595 ms 94248 KB Output is correct
26 Correct 622 ms 92772 KB Output is correct
27 Correct 667 ms 94200 KB Output is correct
28 Correct 738 ms 95076 KB Output is correct
29 Correct 617 ms 94940 KB Output is correct
30 Correct 1116 ms 96760 KB Output is correct
31 Correct 417 ms 76376 KB Output is correct
32 Correct 316 ms 73080 KB Output is correct
33 Correct 869 ms 93816 KB Output is correct
34 Correct 1022 ms 95212 KB Output is correct
35 Correct 1036 ms 90232 KB Output is correct
36 Correct 1020 ms 90124 KB Output is correct
37 Correct 696 ms 95300 KB Output is correct
38 Correct 715 ms 96888 KB Output is correct
39 Correct 815 ms 94488 KB Output is correct
40 Correct 802 ms 94600 KB Output is correct
41 Correct 37 ms 55424 KB Output is correct
42 Correct 1228 ms 99704 KB Output is correct
43 Correct 803 ms 96692 KB Output is correct
44 Correct 964 ms 98036 KB Output is correct
45 Correct 1067 ms 93364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 55416 KB Output is correct
2 Correct 40 ms 55416 KB Output is correct
3 Correct 38 ms 55416 KB Output is correct
4 Correct 32 ms 55416 KB Output is correct
5 Correct 32 ms 55416 KB Output is correct
6 Correct 31 ms 55416 KB Output is correct
7 Correct 33 ms 55416 KB Output is correct
8 Correct 32 ms 55424 KB Output is correct
9 Correct 36 ms 55416 KB Output is correct
10 Correct 32 ms 55416 KB Output is correct
11 Correct 32 ms 55416 KB Output is correct
12 Correct 31 ms 55424 KB Output is correct
13 Correct 35 ms 55424 KB Output is correct
14 Correct 32 ms 55424 KB Output is correct
15 Correct 36 ms 55416 KB Output is correct
16 Correct 32 ms 55416 KB Output is correct
17 Correct 37 ms 55672 KB Output is correct
18 Correct 39 ms 55800 KB Output is correct
19 Correct 40 ms 55800 KB Output is correct
20 Correct 39 ms 55932 KB Output is correct
21 Correct 39 ms 55808 KB Output is correct
22 Correct 39 ms 55680 KB Output is correct
23 Correct 39 ms 55672 KB Output is correct
24 Correct 686 ms 92648 KB Output is correct
25 Correct 595 ms 94248 KB Output is correct
26 Correct 622 ms 92772 KB Output is correct
27 Correct 667 ms 94200 KB Output is correct
28 Correct 738 ms 95076 KB Output is correct
29 Correct 617 ms 94940 KB Output is correct
30 Correct 1116 ms 96760 KB Output is correct
31 Correct 417 ms 76376 KB Output is correct
32 Correct 316 ms 73080 KB Output is correct
33 Correct 869 ms 93816 KB Output is correct
34 Correct 1022 ms 95212 KB Output is correct
35 Correct 1036 ms 90232 KB Output is correct
36 Correct 1020 ms 90124 KB Output is correct
37 Correct 696 ms 95300 KB Output is correct
38 Correct 715 ms 96888 KB Output is correct
39 Correct 815 ms 94488 KB Output is correct
40 Correct 802 ms 94600 KB Output is correct
41 Correct 37 ms 55424 KB Output is correct
42 Correct 1228 ms 99704 KB Output is correct
43 Correct 803 ms 96692 KB Output is correct
44 Correct 964 ms 98036 KB Output is correct
45 Correct 1067 ms 93364 KB Output is correct
46 Correct 3415 ms 201920 KB Output is correct
47 Correct 3458 ms 203236 KB Output is correct
48 Correct 4008 ms 202032 KB Output is correct
49 Correct 4066 ms 202204 KB Output is correct
50 Correct 6997 ms 215340 KB Output is correct
51 Correct 4457 ms 198892 KB Output is correct
52 Correct 5428 ms 201952 KB Output is correct
53 Correct 6454 ms 211564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 798 ms 95152 KB Output is correct
2 Correct 795 ms 96976 KB Output is correct
3 Correct 651 ms 96092 KB Output is correct
4 Correct 642 ms 92280 KB Output is correct
5 Correct 32 ms 55424 KB Output is correct
6 Correct 744 ms 96032 KB Output is correct
7 Correct 383 ms 77020 KB Output is correct
8 Correct 277 ms 75000 KB Output is correct
9 Correct 672 ms 95788 KB Output is correct
10 Correct 747 ms 90908 KB Output is correct
11 Correct 599 ms 91612 KB Output is correct
12 Correct 32 ms 55416 KB Output is correct
13 Correct 40 ms 55416 KB Output is correct
14 Correct 38 ms 55416 KB Output is correct
15 Correct 32 ms 55416 KB Output is correct
16 Correct 32 ms 55416 KB Output is correct
17 Correct 31 ms 55416 KB Output is correct
18 Correct 33 ms 55416 KB Output is correct
19 Correct 32 ms 55424 KB Output is correct
20 Correct 36 ms 55416 KB Output is correct
21 Correct 32 ms 55416 KB Output is correct
22 Correct 32 ms 55416 KB Output is correct
23 Correct 31 ms 55424 KB Output is correct
24 Correct 35 ms 55424 KB Output is correct
25 Correct 32 ms 55424 KB Output is correct
26 Correct 36 ms 55416 KB Output is correct
27 Correct 32 ms 55416 KB Output is correct
28 Correct 37 ms 55672 KB Output is correct
29 Correct 39 ms 55800 KB Output is correct
30 Correct 40 ms 55800 KB Output is correct
31 Correct 39 ms 55932 KB Output is correct
32 Correct 39 ms 55808 KB Output is correct
33 Correct 39 ms 55680 KB Output is correct
34 Correct 39 ms 55672 KB Output is correct
35 Correct 686 ms 92648 KB Output is correct
36 Correct 595 ms 94248 KB Output is correct
37 Correct 622 ms 92772 KB Output is correct
38 Correct 667 ms 94200 KB Output is correct
39 Correct 738 ms 95076 KB Output is correct
40 Correct 617 ms 94940 KB Output is correct
41 Correct 1116 ms 96760 KB Output is correct
42 Correct 417 ms 76376 KB Output is correct
43 Correct 316 ms 73080 KB Output is correct
44 Correct 869 ms 93816 KB Output is correct
45 Correct 1022 ms 95212 KB Output is correct
46 Correct 1036 ms 90232 KB Output is correct
47 Correct 1020 ms 90124 KB Output is correct
48 Correct 696 ms 95300 KB Output is correct
49 Correct 715 ms 96888 KB Output is correct
50 Correct 815 ms 94488 KB Output is correct
51 Correct 802 ms 94600 KB Output is correct
52 Correct 37 ms 55424 KB Output is correct
53 Correct 1228 ms 99704 KB Output is correct
54 Correct 803 ms 96692 KB Output is correct
55 Correct 964 ms 98036 KB Output is correct
56 Correct 1067 ms 93364 KB Output is correct
57 Incorrect 704 ms 96228 KB Output isn't correct
58 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 798 ms 95152 KB Output is correct
2 Correct 795 ms 96976 KB Output is correct
3 Correct 651 ms 96092 KB Output is correct
4 Correct 642 ms 92280 KB Output is correct
5 Correct 32 ms 55424 KB Output is correct
6 Correct 744 ms 96032 KB Output is correct
7 Correct 383 ms 77020 KB Output is correct
8 Correct 277 ms 75000 KB Output is correct
9 Correct 672 ms 95788 KB Output is correct
10 Correct 747 ms 90908 KB Output is correct
11 Correct 599 ms 91612 KB Output is correct
12 Correct 32 ms 55416 KB Output is correct
13 Correct 40 ms 55416 KB Output is correct
14 Correct 38 ms 55416 KB Output is correct
15 Correct 32 ms 55416 KB Output is correct
16 Correct 32 ms 55416 KB Output is correct
17 Correct 31 ms 55416 KB Output is correct
18 Correct 33 ms 55416 KB Output is correct
19 Correct 32 ms 55424 KB Output is correct
20 Correct 36 ms 55416 KB Output is correct
21 Correct 32 ms 55416 KB Output is correct
22 Correct 32 ms 55416 KB Output is correct
23 Correct 31 ms 55424 KB Output is correct
24 Correct 35 ms 55424 KB Output is correct
25 Correct 32 ms 55424 KB Output is correct
26 Correct 36 ms 55416 KB Output is correct
27 Correct 32 ms 55416 KB Output is correct
28 Correct 37 ms 55672 KB Output is correct
29 Correct 39 ms 55800 KB Output is correct
30 Correct 40 ms 55800 KB Output is correct
31 Correct 39 ms 55932 KB Output is correct
32 Correct 39 ms 55808 KB Output is correct
33 Correct 39 ms 55680 KB Output is correct
34 Correct 39 ms 55672 KB Output is correct
35 Correct 686 ms 92648 KB Output is correct
36 Correct 595 ms 94248 KB Output is correct
37 Correct 622 ms 92772 KB Output is correct
38 Correct 667 ms 94200 KB Output is correct
39 Correct 738 ms 95076 KB Output is correct
40 Correct 617 ms 94940 KB Output is correct
41 Correct 1116 ms 96760 KB Output is correct
42 Correct 417 ms 76376 KB Output is correct
43 Correct 316 ms 73080 KB Output is correct
44 Correct 869 ms 93816 KB Output is correct
45 Correct 1022 ms 95212 KB Output is correct
46 Correct 1036 ms 90232 KB Output is correct
47 Correct 1020 ms 90124 KB Output is correct
48 Correct 696 ms 95300 KB Output is correct
49 Correct 715 ms 96888 KB Output is correct
50 Correct 815 ms 94488 KB Output is correct
51 Correct 802 ms 94600 KB Output is correct
52 Correct 37 ms 55424 KB Output is correct
53 Correct 1228 ms 99704 KB Output is correct
54 Correct 803 ms 96692 KB Output is correct
55 Correct 964 ms 98036 KB Output is correct
56 Correct 1067 ms 93364 KB Output is correct
57 Correct 3415 ms 201920 KB Output is correct
58 Correct 3458 ms 203236 KB Output is correct
59 Correct 4008 ms 202032 KB Output is correct
60 Correct 4066 ms 202204 KB Output is correct
61 Correct 6997 ms 215340 KB Output is correct
62 Correct 4457 ms 198892 KB Output is correct
63 Correct 5428 ms 201952 KB Output is correct
64 Correct 6454 ms 211564 KB Output is correct
65 Incorrect 704 ms 96228 KB Output isn't correct
66 Halted 0 ms 0 KB -