Submission #997301

#TimeUsernameProblemLanguageResultExecution timeMemory
997301LOLOLOFuel Station (NOI20_fuelstation)C++17
100 / 100
372 ms47012 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define f first #define s second #define pb push_back #define ep emplace #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin()) #define mem(f,x) memset(f , x , sizeof(f)) #define sz(x) (ll)(x).size() #define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b)) #define mxx *max_element #define mnn *min_element #define cntbit(x) __builtin_popcountll(x) #define len(x) (int)(x.length()) const int N = 3e5 + 10; ll seg[N * 4], laz[N * 4]; void push(int id) { ll t = laz[id]; laz[id * 2] += t; laz[id * 2 + 1] += t; seg[id * 2] += t; seg[id * 2 + 1] += t; laz[id] = 0; } void upd(int id, int l, int r, int u, int v, ll add) { if (l > v || r < u) return; if (l >= u && r <= v) { seg[id] += add; laz[id] += add; return; } push(id); int m = (l + r) / 2; upd(id * 2, l, m, u, v, add); upd(id * 2 + 1, m + 1, r, u, v, add); seg[id] = min(seg[id * 2], seg[id * 2 + 1]); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, d; cin >> n >> d; vector <int> pos; vector < vector <int>> station; for (int i = 1; i <= n; i++) { int x, a, b; cin >> x >> a >> b; station.pb({b, x, a}); pos.pb(x); } pos.pb(0); pos.pb(d); uniquev(pos); sort(all(station), greater <vector <int>> ()); for (int i = 0; i < sz(pos); i++) { upd(1, 0, sz(pos) - 1, i, i, -pos[i]); } int ans = d; for (auto x : station) { int p = upper_bound(all(pos), x[1]) - pos.begin(); upd(1, 0, sz(pos) - 1, p, sz(pos) - 1, x[2]); if (abs(seg[1]) <= x[0]) { ans = min(ans, (int)abs(seg[1])); } } cout << ans << '\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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...