Submission #719574

#TimeUsernameProblemLanguageResultExecution timeMemory
719574kymTreatment Project (JOI20_treatment)C++14
4 / 100
310 ms113804 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define FOR(i,s,e) for(int i = s; i <= (int)e; ++i) #define DEC(i,s,e) for(int i = s; i >= (int)e; --i) #define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0); #ifdef LOCAL #define db(x) cerr << #x << "=" << x << "\n" #define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n" #define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n" #define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n" #define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{" << ite.f << ',' << ite.s << "} "; cerr << "\n" #define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n" #define reach cerr << "LINE: " << __LINE__ << "\n"; #else #define reach #define db(x) #define db2(x,y) #define db3(a,b,c) #define dbv(v) #define dbvp(v) #define dba(a,ss,ee) #endif mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define f first #define s second #define g0(x) get<0>(x) #define g1(x) get<1>(x) #define g2(x) get<2>(x) #define g3(x) get<3>(x) typedef pair <int, int> pi; typedef tuple<int,int,int> ti3; typedef tuple<int,int,int,int> ti4; int rand(int a, int b) { return a + rng() % (b-a+1); } const int MOD = 1e9 + 7; const int inf = (int)1e9 + 500; const long long oo = (long long)1e18 + 500; template <typename T> void chmax(T& a, const T b) { a=max(a,b); } template <typename T> void chmin(T& a, const T b) { a=min(a,b); } const int MAXN = 100005; int n,m; struct item { int t,l,r,c; } T[MAXN]; vector<pi> vec; map<int,multiset<int>> S; // {right diag, cost} priority_queue<pi,vector<pi>,greater<pi>> pq; // {right diagonal, index} struct node { int s,e,m,val; node *l=nullptr, *r=nullptr; node(int _s, int _e) { s=_s;e=_e; m=floor(((double)s+e)/2); val=oo; } int query(int x, int y) { if(s==x&&e==y)return val; if(x>m) return (r?r->query(x,y):oo); if(y<=m) return (l?l->query(x,y):oo); else return min(l?l->query(x,m):oo, r?r->query(m+1,y):oo); } void update(int x, int nval){ if(s==e){ val=nval; return; } if(x>m){ if(r==nullptr)r=new node(m+1,e); r->update(x,nval); } else { if(l==nullptr)l=new node(s,m); l->update(x,nval); } val=min(l?l->val:oo,r?r->val:oo); } }*seg=new node(-2*inf,2*inf); int dp[MAXN]; int ans=oo; int32_t main() { IAMSPEED cin >> n >> m; FOR(i,1,m) cin >> T[i].t >> T[i].l >> T[i].r >> T[i].c; FOR(i,1,m)T[i].r++; FOR(i,1,m) { if(T[i].l == 1)vec.pb({-inf-T[i].t,i}); else vec.pb({T[i].l-T[i].t,i}); } sort(all(vec)); for(auto &x:vec){ db(x.s); while(pq.size() && pq.top().f<x.f) { pi cur=pq.top(); pq.pop(); db2(cur.f,cur.s); int idx=cur.s; int rr=T[idx].r+T[idx].t; S[rr].erase(S[rr].find(dp[idx])); if(S[rr].size())seg->update(rr,*S[rr].begin()); else seg->update(rr,oo); } int sz=T[x.s].r - T[x.s].l; int l0=T[x.s].l, l1=T[x.s].l+sz; int t0=T[x.s].t, t1=t0+sz; int r0=T[x.s].r, r1=T[x.s].r-sz; // remove the expiring ones. int &cost = dp[x.s]; cost = T[x.s].c; if(T[x.s].l != 1) { // cannot start from this segment. int L=l0+t0; int R=l1+t1; cost += seg->query(L,R); // the downwards diagonal } if(T[x.s].r==n+1)chmin(ans,cost); db3(r0,t0,cost); S[r0+t0].insert(cost); seg->update(r0+t0,*S[r0+t0].begin()); pq.push({r0-t0, x.s}); } if(ans!=oo)cout<<ans; else cout<<-1; return (0-0) ; }

Compilation message (stderr)

treatment.cpp: In function 'int32_t main()':
treatment.cpp:109:20: warning: unused variable 'r1' [-Wunused-variable]
  109 |   int r0=T[x.s].r, r1=T[x.s].r-sz;
      |                    ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...