Submission #1106026

#TimeUsernameProblemLanguageResultExecution timeMemory
1106026HiepVu217Fuel Station (NOI20_fuelstation)C++17
100 / 100
249 ms29512 KiB
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 17; int n, d; long long st[4 * N], lz[4 * N], ans; bool t; struct dta { int x, a, b, id; bool operator < (const dta& other) const { return (t ? b > other.b : x < other.x); } } fuel[N]; void down (int id) { st[id * 2] += lz[id]; lz[id * 2] += lz[id]; st[id * 2 + 1] += lz[id]; lz[id * 2 + 1] += lz[id]; lz[id] = 0; } void update (int id, int l, int r, int u, int v, int x) { if (v < l || r < u) { return; } if (u <= l && r <= v) { st[id] += x, lz[id] += x; return; } int mid = l + r >> 1; down(id); update (id * 2, l, mid, u, v, x); update (id * 2 + 1, mid + 1, r, u, v, x); st[id] = max (st[id * 2], st[id * 2 + 1]); } long long get (int id, int l, int r, int u, int v) { if (v < l || r < u) { return 0; } if (u <= l && r <= v) { return st[id]; } int mid = l + r >> 1; down(id); return max (get (id * 2, l, mid, u, v), get (id * 2 + 1, mid + 1, r, u, v)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> d; for (int i = 1, x, a, b; i <= n; ++i) { cin >> x >> a >> b; fuel[i] = {x, a, b, 0}; } sort (fuel + 1, fuel + n + 1); fuel[n + 1] = {d, 0, 0}; for (int i = 1; i <= n + 1; ++i) { fuel[i].id = i; update (1, 1, n + 1, i, i, fuel[i].x); } t = 1; sort (fuel + 1, fuel + n + 1); ans = st[1]; for (int i = 1; i <= n + 1; ++i) { auto [x, a, b, id] = fuel[i]; update (1, 1, n + 1, id + 1, n + 1, -a); if (st[1] <= b) { ans = min (ans, st[1]); } } cout << ans; }

Compilation message (stderr)

FuelStation.cpp: In function 'void update(int, int, int, int, int, int)':
FuelStation.cpp:33:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |     int mid = l + r >> 1;
      |               ~~^~~
FuelStation.cpp: In function 'long long int get(int, int, int, int, int)':
FuelStation.cpp:49:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |     int mid = l + r >> 1;
      |               ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...