Submission #160386

#TimeUsernameProblemLanguageResultExecution timeMemory
160386godwindArt Exhibition (JOI18_art)C++17
100 / 100
815 ms61896 KiB
#pragma GCC optimize("Ofast") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("fast-math") #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native") #include <iostream> #include <vector> #include <algorithm> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <stdio.h> #include <cstdio> #include <math.h> #include <cmath> #include <string> #include <cstring> #include <queue> #include <deque> #include <random> #include <iomanip> #include <bitset> using namespace std; template<typename T> void uin(T &a, T b) { if (b < a) { a = b; } } template<typename T> void uax(T &a, T b) { if (b > a) { a = b; } } #define int long long #define left left228 #define right right228 #define prev prev228 #define list list228 #define mp make_pair #define all(v) v.begin(), v.end() #define forn(i, n) for (int i = 0; i < (int)n; ++i) #define firn(i, n) for (int i = 1; i < (int)n; ++i) #define x first #define y second const int N = 500 * 1000 + 228; int a[N], b[N]; int X; vector< pair<int, int> > crd; struct node { int mx, mod; int l, r; node() { mx = mod = l = r = 0; } }; vector< node > d; void build(int l, int r, int v = 1) { d[v].l = l, d[v].r = r; if (l == r) { d[v].mx = crd.back().first - crd[l - 1].first; } else { int m = (l + r) >> 1; build(l, m, v << 1); build(m + 1, r, v << 1 | 1); d[v].mx = max(d[v << 1].mx, d[v << 1 | 1].mx); } } int gets(int v) { return d[v].mx + d[v].mod; } void push(int v) { d[v << 1].mod += d[v].mod; d[v << 1 | 1].mod += d[v].mod; d[v].mod = 0; d[v].mx = max(gets(v << 1), gets(v << 1 | 1)); } void update(int l, int r, int x, int v = 1) { if (l > r || d[v].l > r || d[v].r < l) return; if (l <= d[v].l && d[v].r <= r) { d[v].mod += x; } else { push(v); update(l, r, x, v << 1); update(l, r, x, v << 1 | 1); d[v].mx = max(gets(v << 1), gets(v << 1 | 1)); } } int get(int l, int r, int v = 1) { if (l > r || d[v].l > r || d[v].r < l) return 0; if (l <= d[v].l && d[v].r <= r) return gets(v); push(v); return max(get(l, r, v << 1), get(l, r, v << 1 | 1)); } void init(int n) { int ss = 1; while (ss < n) ss <<= 1; ss <<= 1; d.resize(ss + 3, node()); build(1, n); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i] >> b[i]; crd.push_back({a[i], b[i]}); } sort(crd.begin(), crd.end()); init(n); int res = 0; int pv = crd.back().first; int delta = 0; for (int i = n; i; --i) { delta += crd[i - 1].first - pv; pv = crd[i - 1].first; update(i, n, crd[i - 1].second); uax(res, delta + get(i, n)); } cout << res << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...