Submission #1103835

#TimeUsernameProblemLanguageResultExecution timeMemory
1103835haianhnguyen08102007Fuel Station (NOI20_fuelstation)C++17
26 / 100
347 ms60716 KiB
#include <bits/stdc++.h> using namespace std; vector <pair <long long, long long>> vec; struct node { long long s, e, m; long long mn, lz; node *l, *r; node (long long _s, long long _e) : s(_s), e(_e), m((_s+_e)/2), lz(0) { if (s==e) { mn-= vec[s].first; return; } l=new node(s, m); r=new node(m+1, e); mn=min(l->mn, r->mn); } void prop() { l->update(s, m, lz); r->update(m+1, e, lz); lz = 0; mn=min(l->mn, r->mn); } void update(long long x, long long y, long long v) { if (x > y) return; if (x<=s && y>=e) { mn+=v; lz+=v; return; } if (lz!=0) prop(); if (x<=m) l->update(x, y, v); if (y>=m+1) r->update(x, y, v); mn=min(l->mn, r->mn); } }; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("FFUEL.INP", "r", stdin); // freopen("FFUEL.OUT", "w", stdout); long long n, d, x, a, b, ans; vector <tuple <long long, long long, long long>> vec2; cin>>n>>d; ans=d; for (long long i=0; i<n; i++) { cin>>x>>a>>b; vec.emplace_back(x, i); vec2.emplace_back(b, a, x); } vec.emplace_back(d, n); vec2.emplace_back(2000000000, 0, d); sort(vec.begin(), vec.end()); long long cnt = n+1; for (long long i=n; i>=0; i--) { if (i!=n && vec[i].first != vec[i+1].first) cnt = i+1; get<2>(vec2[vec[i].second]) = cnt; } sort(vec2.begin(), vec2.end()); node *root = new node(0, n); for (long long i = 0; i<n; i++) { root->update(get<2>(vec2[i]), n, get<1>(vec2[i])); } long long left = 0; for (long long i = 0; i<=n; i++) { root->update(0, n, get<0>(vec2[i]) - (i==0 ? 0 : get<0>(vec2[i-1]))); if (i<n-1 && get<0>(vec2[i])==get<0>(vec2[i+1])) continue; while (get<0>(vec2[left]) != get<0>(vec2[i])) { root->update(get<2>(vec2[left]), n, -get<1>(vec2[left])); left++; } if (root->mn < 0) continue; ans=min(ans, get<0>(vec2[i]) - root->mn); } cout<<ans; 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...