답안 #234945

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
234945 2020-05-26T11:55:53 Z Atalasion Art Exhibition (JOI18_art) C++14
100 / 100
937 ms 37552 KB
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-O2")


using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 500000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000000000000010;
const ll LOG = 25;

struct per{
	ll a, b;
};
ll seg[N << 2], lazy[N << 2], n;
per A[N];

void modify(int id, ll x){
	seg[id] += x;
	lazy[id] += x;
}

void shift(int id){
	modify(id << 1, lazy[id]);
	modify(id << 1 | 1, lazy[id]);
	lazy[id] = 0;
}


void add(int id, int lq, int rq, ll x, int l, int r){
	if (rq <= l || r <= lq)return;
	if (lq <= l && r <= rq){
		modify(id, x);
		return;
	}
	int md = (l +r) >> 1;
	shift(id);
	add(id << 1, lq, rq, x, l, md);
	add(id << 1 | 1, lq, rq, x, md, r);
	seg[id] = max(seg[id << 1], seg[id << 1 | 1]);
}

bool cmp(per x, per y){
	return x.a < y.a;
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> A[i].a >> A[i].b;
	}
	sort(A + 1, A + n + 1, cmp);
	ll ans = 0;
	for (int i = 1; i <= n; i++){
		add(1, i, n + 1, A[i].b, 1, n + 1);
		add(1, i, i + 1, -A[i].a, 1, n + 1);
	}
	for (int i = 1; i <= n; i++){
		add(1, i, n + 1, A[i].a, 1, n + 1);
		ans = max(ans, seg[1]);
		add(1, i, n + 1, -A[i].b, 1, n + 1);
		add(1, i, n + 1, -A[i].a, 1, n + 1);
	}
	cout << ans;







	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 6 ms 384 KB Output is correct
27 Correct 15 ms 896 KB Output is correct
28 Correct 11 ms 896 KB Output is correct
29 Correct 11 ms 768 KB Output is correct
30 Correct 12 ms 768 KB Output is correct
31 Correct 11 ms 896 KB Output is correct
32 Correct 11 ms 896 KB Output is correct
33 Correct 11 ms 768 KB Output is correct
34 Correct 12 ms 768 KB Output is correct
35 Correct 11 ms 768 KB Output is correct
36 Correct 11 ms 768 KB Output is correct
37 Correct 11 ms 768 KB Output is correct
38 Correct 11 ms 896 KB Output is correct
39 Correct 11 ms 768 KB Output is correct
40 Correct 11 ms 768 KB Output is correct
41 Correct 12 ms 768 KB Output is correct
42 Correct 11 ms 896 KB Output is correct
43 Correct 11 ms 768 KB Output is correct
44 Correct 11 ms 768 KB Output is correct
45 Correct 12 ms 760 KB Output is correct
46 Correct 11 ms 768 KB Output is correct
47 Correct 11 ms 768 KB Output is correct
48 Correct 11 ms 768 KB Output is correct
49 Correct 11 ms 896 KB Output is correct
50 Correct 11 ms 768 KB Output is correct
51 Correct 11 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 6 ms 384 KB Output is correct
27 Correct 15 ms 896 KB Output is correct
28 Correct 11 ms 896 KB Output is correct
29 Correct 11 ms 768 KB Output is correct
30 Correct 12 ms 768 KB Output is correct
31 Correct 11 ms 896 KB Output is correct
32 Correct 11 ms 896 KB Output is correct
33 Correct 11 ms 768 KB Output is correct
34 Correct 12 ms 768 KB Output is correct
35 Correct 11 ms 768 KB Output is correct
36 Correct 11 ms 768 KB Output is correct
37 Correct 11 ms 768 KB Output is correct
38 Correct 11 ms 896 KB Output is correct
39 Correct 11 ms 768 KB Output is correct
40 Correct 11 ms 768 KB Output is correct
41 Correct 12 ms 768 KB Output is correct
42 Correct 11 ms 896 KB Output is correct
43 Correct 11 ms 768 KB Output is correct
44 Correct 11 ms 768 KB Output is correct
45 Correct 12 ms 760 KB Output is correct
46 Correct 11 ms 768 KB Output is correct
47 Correct 11 ms 768 KB Output is correct
48 Correct 11 ms 768 KB Output is correct
49 Correct 11 ms 896 KB Output is correct
50 Correct 11 ms 768 KB Output is correct
51 Correct 11 ms 768 KB Output is correct
52 Correct 915 ms 37240 KB Output is correct
53 Correct 909 ms 37500 KB Output is correct
54 Correct 924 ms 37300 KB Output is correct
55 Correct 904 ms 37368 KB Output is correct
56 Correct 906 ms 37368 KB Output is correct
57 Correct 914 ms 37368 KB Output is correct
58 Correct 920 ms 37344 KB Output is correct
59 Correct 905 ms 37496 KB Output is correct
60 Correct 918 ms 37368 KB Output is correct
61 Correct 889 ms 37344 KB Output is correct
62 Correct 893 ms 37372 KB Output is correct
63 Correct 908 ms 37368 KB Output is correct
64 Correct 872 ms 37412 KB Output is correct
65 Correct 937 ms 37368 KB Output is correct
66 Correct 918 ms 37552 KB Output is correct
67 Correct 925 ms 37240 KB Output is correct
68 Correct 916 ms 37288 KB Output is correct