Submission #336510

# Submission time Handle Problem Language Result Execution time Memory
336510 2020-12-15T13:24:42 Z Galebickosikasa Art Exhibition (JOI18_art) C++17
100 / 100
458 ms 41440 KB
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
// #pragma comment(linker, "/stack:200000000"]
 
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <random>
#include <fstream>
#include <sstream>
#include <chrono>

#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define hm unordered_map 
#define pii pair<int, int>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define cinv(v) for (auto& x: v) cin >> x
#define fr(i, n) for (int i = 0; i < n; ++i)
#define fl(i, l, n) for (int i = l; i < n; ++i)

#define int ll

template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}

using namespace std;

#ifdef LOCAL
	#define dbg(x) cerr << #x << " : " << x << '\n'
	const int maxn = 20;
#else 
	#define dbg(x)
	const int maxn = 2e5 + 20;
#endif

//tg: @galebickosikasa
 
ostream& operator << (ostream& out, const pii& v) {
	out << v.fi << ", " << v.se;
	return out;
}

template<typename T> ostream& operator << (ostream& out, const vector<T>& v) {
    for (auto& x: v) out << x << " ";
    return out;
}

istream& operator >> (istream& in, pii& a) {
	in >> a.fi >> a.se;
	return in;
}

const ll inf = (ll) 2e9;
const ld pi = asin (1) * 2;
const ld eps = 1e-8;
const ll mod = (ll)1e9 + 7;
const ll ns = 97;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

struct tree {
	vector<int> t, assign;
	int size = 0, capacity;

	tree (vector<int>& v) {
		while ((1<<size) < sz (v)) ++size;
		++size;
		size = (1<<size);
		capacity = (size>>1);
		t = assign = vector<int> (size);
		for (int i = 0; i < sz (v); ++i) t[i + capacity] = v[i];
		for (int i = capacity - 1; i > 0; --i) t[i] = max (t[i * 2], t[i * 2 + 1]);
	}

	inline void push (int v) {
		assign[v * 2] += assign[v];
		assign[v * 2 + 1] += assign[v];
		assign[v] = 0;
	}

	inline void render (int v) {
		t[v] = max (t[v * 2] + assign[v * 2], t[v * 2 + 1] + assign[v * 2 + 1]);
	}

	int get (int cur, int left, int right, int l, int r) {
		if (cur >= size) return 0;
		if (left > r || right < l) return 0;
		if (l <= left && r >= right) return t[cur] + assign[cur];
		push (cur);
		int ans = max (get (cur * 2, left, (left + right) / 2, l, r), get (cur * 2 + 1, (left + right) / 2 + 1, right, l, r));
		render (cur);
		return ans;
	}

	inline int get (int l, int r) {
		return get (1, 0, capacity - 1, l, r);
	}

	void add (int cur, int left, int right, int l, int r, int x) {
		if (cur >= size) return;
		if (left > r || right < l) return;
		if (l <= left && r >= right) assign[cur] += x;
		else {
			push (cur);
			add (cur * 2, left, (left + right) / 2, l, r, x);
			add (cur * 2 + 1, (left + right) / 2 + 1, right, l, r, x);
			render (cur);
		}
	}

	inline void add (int l, int r, int x) {
		add (1, 0, capacity - 1, l, r, x);
	}
};

struct kek {
	int a, b;

	inline bool operator < (const kek& other) const {
		return a < other.a;
	}
};

signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n;
	cin >> n;
	vector<kek> goo (n);
	for (auto& x: goo) cin >> x.a >> x.b;
	sort (all (goo));
	vector<int> v;
	for (auto& x: goo) v.pb (x.a);
	tree t (v);
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		t.add (0, i, goo[i].b);
		chkmax (ans, t.get (0, i) - goo[i].a);
	}
	cout << ans << '\n';






}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 396 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 396 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 396 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 4 ms 876 KB Output is correct
28 Correct 4 ms 876 KB Output is correct
29 Correct 4 ms 876 KB Output is correct
30 Correct 5 ms 876 KB Output is correct
31 Correct 5 ms 876 KB Output is correct
32 Correct 4 ms 876 KB Output is correct
33 Correct 4 ms 920 KB Output is correct
34 Correct 4 ms 876 KB Output is correct
35 Correct 4 ms 876 KB Output is correct
36 Correct 4 ms 876 KB Output is correct
37 Correct 4 ms 876 KB Output is correct
38 Correct 4 ms 876 KB Output is correct
39 Correct 4 ms 876 KB Output is correct
40 Correct 4 ms 876 KB Output is correct
41 Correct 4 ms 876 KB Output is correct
42 Correct 4 ms 876 KB Output is correct
43 Correct 4 ms 876 KB Output is correct
44 Correct 4 ms 876 KB Output is correct
45 Correct 4 ms 876 KB Output is correct
46 Correct 4 ms 876 KB Output is correct
47 Correct 4 ms 876 KB Output is correct
48 Correct 4 ms 876 KB Output is correct
49 Correct 4 ms 876 KB Output is correct
50 Correct 4 ms 876 KB Output is correct
51 Correct 4 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 396 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 4 ms 876 KB Output is correct
28 Correct 4 ms 876 KB Output is correct
29 Correct 4 ms 876 KB Output is correct
30 Correct 5 ms 876 KB Output is correct
31 Correct 5 ms 876 KB Output is correct
32 Correct 4 ms 876 KB Output is correct
33 Correct 4 ms 920 KB Output is correct
34 Correct 4 ms 876 KB Output is correct
35 Correct 4 ms 876 KB Output is correct
36 Correct 4 ms 876 KB Output is correct
37 Correct 4 ms 876 KB Output is correct
38 Correct 4 ms 876 KB Output is correct
39 Correct 4 ms 876 KB Output is correct
40 Correct 4 ms 876 KB Output is correct
41 Correct 4 ms 876 KB Output is correct
42 Correct 4 ms 876 KB Output is correct
43 Correct 4 ms 876 KB Output is correct
44 Correct 4 ms 876 KB Output is correct
45 Correct 4 ms 876 KB Output is correct
46 Correct 4 ms 876 KB Output is correct
47 Correct 4 ms 876 KB Output is correct
48 Correct 4 ms 876 KB Output is correct
49 Correct 4 ms 876 KB Output is correct
50 Correct 4 ms 876 KB Output is correct
51 Correct 4 ms 876 KB Output is correct
52 Correct 454 ms 41348 KB Output is correct
53 Correct 458 ms 41436 KB Output is correct
54 Correct 453 ms 41440 KB Output is correct
55 Correct 450 ms 41352 KB Output is correct
56 Correct 448 ms 41440 KB Output is correct
57 Correct 455 ms 41440 KB Output is correct
58 Correct 454 ms 41312 KB Output is correct
59 Correct 450 ms 41440 KB Output is correct
60 Correct 449 ms 41436 KB Output is correct
61 Correct 455 ms 41308 KB Output is correct
62 Correct 452 ms 41440 KB Output is correct
63 Correct 451 ms 41312 KB Output is correct
64 Correct 453 ms 41440 KB Output is correct
65 Correct 447 ms 41440 KB Output is correct
66 Correct 449 ms 41436 KB Output is correct
67 Correct 451 ms 41440 KB Output is correct
68 Correct 453 ms 41312 KB Output is correct