Submission #1083905

#TimeUsernameProblemLanguageResultExecution timeMemory
1083905May27_thArt Exhibition (JOI18_art)C++17
0 / 100
1 ms348 KiB
#include<bits/stdc++.h> using namespace std; #define i64 long long #define mp make_pair #define pb push_back #define all(x) (x).begin(), (x).end() struct Tree{ int n; vector<int64_t>lazy; vector<int64_t>st; Tree(int _n, int64_t _v): n(_n), st(_n * 4, _v), lazy(_n * 4, _v){}; void push(int id){ int64_t add = lazy[id]; lazy[id * 2] += add, st[id * 2] += add; lazy[id * 2 + 1] += add, st[id * 2 + 1] += add; lazy[id] = 0; } void update(int id, int l, int r, int u, int v, int64_t val){ if (v < l || u > r) return; if (u <= l && r <= v) { st[id] += val; // lazy[id] += val; return; } // push(id); int mid = (l + r)/2; update(id * 2, l, mid, u, v, val); update(id * 2 + 1, mid + 1, r, u, v, val); st[id] = max(st[id * 2], st[id * 2 + 1]); } i64 get(int id, int l, int r, int u, int v) { if (v < l || u > r) return 0; if (u <= l && r <= v) return st[id]; int mid = (l + r)/2; return max(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v)); } }; void Solve(void) { int N; cin >> N; Tree sum(N + 5, 0); vector<pair<i64, i64>> pictures(N); vector<i64> pref(N + 2, 0); for (int i = 0; i < N; i ++) { cin >> pictures[i].first >> pictures[i].second; } sort(all(pictures)); for (int i = 0; i < N; i ++) { pref[i + 1] = pref[i] + pictures[i].second; sum.update(1, 1, N, i + 1, i + 1, pref[i + 1] - pictures[i].first); } i64 ans = 0; for (int i = 1; i <= N; i ++) { ans = max(ans, sum.get(1, 1, N, i, N) - pref[i - 1] + pictures[i - 1].first); } cout << ans << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int Tests = 1; // cin >> Tests; while (Tests --) { Solve(); } }

Compilation message (stderr)

art.cpp: In constructor 'Tree::Tree(int, int64_t)':
art.cpp:12:18: warning: 'Tree::st' will be initialized after [-Wreorder]
   12 |   vector<int64_t>st;
      |                  ^~
art.cpp:11:18: warning:   'std::vector<long int> Tree::lazy' [-Wreorder]
   11 |   vector<int64_t>lazy;
      |                  ^~~~
art.cpp:13:3: warning:   when initialized here [-Wreorder]
   13 |   Tree(int _n, int64_t _v): n(_n), st(_n * 4, _v), lazy(_n * 4, _v){};
      |   ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...