Submission #847599

# Submission time Handle Problem Language Result Execution time Memory
847599 2023-09-10T03:45:01 Z Amaarsaa Art Exhibition (JOI18_art) C++14
100 / 100
293 ms 68256 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long ;
ll mid;
struct Node{
	ll Max = 0, Has = 0;
	Node *l, *r; 
};
void Change(Node *P, ll lo, ll hi, ll st, ll fn, ll x) {
	if (st > hi || lo > fn) return ;
	if ( st <= lo && hi <= fn) {
		P -> Max += x;
		P -> Has = 1;
		return ;
	}
	if (!P -> l) P -> l = new Node();
	if (!P -> r) P -> r = new Node();
	mid = (lo + hi)/2;
	if ( P -> Has == 1) {
		P -> l -> Has = 1;
		P -> r -> Has = 1;
		P -> Has = 0;
		P -> l -> Max = P -> Max;
		P -> r -> Max = P -> Max;
	}
	Change(P -> l, lo, mid, st, fn, x);
	Change(P -> r, mid + 1, hi, st, fn, x);
	P -> Max = max ( P -> l -> Max, P -> r -> Max);
}
ll Find(Node *P, ll lo, ll hi, ll st, ll fn) {
	if (st > hi || lo > fn) return 0;
	if ( st <= lo && hi <= fn) {
		return P -> Max;
	}
	if (!P -> l) P -> l = new Node();
	if (!P -> r) P -> r = new Node();
	mid = (lo + hi)/2;
	if ( P -> Has == 1) {
		P -> l -> Has = 1;
		P -> r -> Has = 1;
		P -> Has = 0;
		P -> l -> Max = P -> Max;
		P -> r -> Max = P -> Max;
	}
	Find(P -> l, lo, mid, st, fn);
	Find(P -> r, mid + 1, hi, st, fn);
	P -> Max = max ( P -> l -> Max, P -> r -> Max);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll t, n, m, ans, s, sum, x, y, r, p, i, j;
	
	cin >> n;
	
	vector < pair < ll, ll > > v;
	Node *Tre = new Node();
	for (i = 1; i <= n; i ++) {
		cin >> x >> y;
		v.push_back(make_pair(x, y));
	}
	ans= 0;
	v.push_back(make_pair(0, 0));
	sort(v.begin(), v.end());
	for (i =1; i < v.size(); i ++)  {
		s = v[i].second - (v[i].first - v[i - 1].first);
		Change(Tre, 1, n, 1, i - 1, ll((v[i - 1].first -v[i].first)));
		Change(Tre, 1, n, 1, i, (v[i].second));
		ans = max (ans, Tre -> Max);
	}
	cout << ans << endl;
}

Compilation message

art.cpp: In function 'int main()':
art.cpp:67:15: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |  for (i =1; i < v.size(); i ++)  {
      |             ~~^~~~~~~~~~
art.cpp:54:5: warning: unused variable 't' [-Wunused-variable]
   54 |  ll t, n, m, ans, s, sum, x, y, r, p, i, j;
      |     ^
art.cpp:54:11: warning: unused variable 'm' [-Wunused-variable]
   54 |  ll t, n, m, ans, s, sum, x, y, r, p, i, j;
      |           ^
art.cpp:54:19: warning: variable 's' set but not used [-Wunused-but-set-variable]
   54 |  ll t, n, m, ans, s, sum, x, y, r, p, i, j;
      |                   ^
art.cpp:54:22: warning: unused variable 'sum' [-Wunused-variable]
   54 |  ll t, n, m, ans, s, sum, x, y, r, p, i, j;
      |                      ^~~
art.cpp:54:33: warning: unused variable 'r' [-Wunused-variable]
   54 |  ll t, n, m, ans, s, sum, x, y, r, p, i, j;
      |                                 ^
art.cpp:54:36: warning: unused variable 'p' [-Wunused-variable]
   54 |  ll t, n, m, ans, s, sum, x, y, r, p, i, j;
      |                                    ^
art.cpp:54:42: warning: unused variable 'j' [-Wunused-variable]
   54 |  ll t, n, m, ans, s, sum, x, y, r, p, i, j;
      |                                          ^
art.cpp: In function 'll Find(Node*, ll, ll, ll, ll)':
art.cpp:48:11: warning: control reaches end of non-void function [-Wreturn-type]
   48 |  P -> Max = max ( P -> l -> Max, P -> r -> Max);
      |  ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 4 ms 1116 KB Output is correct
28 Correct 3 ms 1116 KB Output is correct
29 Correct 4 ms 1112 KB Output is correct
30 Correct 4 ms 1112 KB Output is correct
31 Correct 3 ms 1116 KB Output is correct
32 Correct 3 ms 976 KB Output is correct
33 Correct 3 ms 1116 KB Output is correct
34 Correct 3 ms 928 KB Output is correct
35 Correct 3 ms 1116 KB Output is correct
36 Correct 3 ms 1116 KB Output is correct
37 Correct 3 ms 1116 KB Output is correct
38 Correct 3 ms 1116 KB Output is correct
39 Correct 4 ms 1112 KB Output is correct
40 Correct 3 ms 1368 KB Output is correct
41 Correct 3 ms 1112 KB Output is correct
42 Correct 3 ms 1116 KB Output is correct
43 Correct 3 ms 1116 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 3 ms 976 KB Output is correct
46 Correct 3 ms 1116 KB Output is correct
47 Correct 3 ms 1116 KB Output is correct
48 Correct 3 ms 1116 KB Output is correct
49 Correct 3 ms 1116 KB Output is correct
50 Correct 3 ms 1116 KB Output is correct
51 Correct 3 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 4 ms 1116 KB Output is correct
28 Correct 3 ms 1116 KB Output is correct
29 Correct 4 ms 1112 KB Output is correct
30 Correct 4 ms 1112 KB Output is correct
31 Correct 3 ms 1116 KB Output is correct
32 Correct 3 ms 976 KB Output is correct
33 Correct 3 ms 1116 KB Output is correct
34 Correct 3 ms 928 KB Output is correct
35 Correct 3 ms 1116 KB Output is correct
36 Correct 3 ms 1116 KB Output is correct
37 Correct 3 ms 1116 KB Output is correct
38 Correct 3 ms 1116 KB Output is correct
39 Correct 4 ms 1112 KB Output is correct
40 Correct 3 ms 1368 KB Output is correct
41 Correct 3 ms 1112 KB Output is correct
42 Correct 3 ms 1116 KB Output is correct
43 Correct 3 ms 1116 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 3 ms 976 KB Output is correct
46 Correct 3 ms 1116 KB Output is correct
47 Correct 3 ms 1116 KB Output is correct
48 Correct 3 ms 1116 KB Output is correct
49 Correct 3 ms 1116 KB Output is correct
50 Correct 3 ms 1116 KB Output is correct
51 Correct 3 ms 1116 KB Output is correct
52 Correct 289 ms 68256 KB Output is correct
53 Correct 282 ms 67808 KB Output is correct
54 Correct 282 ms 67980 KB Output is correct
55 Correct 287 ms 67692 KB Output is correct
56 Correct 287 ms 67668 KB Output is correct
57 Correct 285 ms 67724 KB Output is correct
58 Correct 285 ms 67764 KB Output is correct
59 Correct 286 ms 67960 KB Output is correct
60 Correct 289 ms 67740 KB Output is correct
61 Correct 292 ms 68024 KB Output is correct
62 Correct 286 ms 67768 KB Output is correct
63 Correct 293 ms 67868 KB Output is correct
64 Correct 283 ms 67660 KB Output is correct
65 Correct 284 ms 67952 KB Output is correct
66 Correct 291 ms 67768 KB Output is correct
67 Correct 283 ms 67864 KB Output is correct
68 Correct 289 ms 67796 KB Output is correct