Submission #1285960

#TimeUsernameProblemLanguageResultExecution timeMemory
1285960hainam2k9Treatment Project (JOI20_treatment)C++20
100 / 100
206 ms27668 KiB
#include <bits/stdc++.h> #define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0) #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout) #define ll long long #define ull unsigned long long #define i128 __int128 #define db long double #define sz(a) ((int)(a).size()) #define pb emplace_back #define pf emplace_front #define pob pop_back #define pof pop_front #define lb lower_bound #define ub upper_bound #define fi first #define se second #define ins emplace #define mp make_pair using namespace std; const int MOD = 1e9+7, MAXN = 1e5+5; const string NAME = ""; struct Project{ int t,l,r,cost; }a[MAXN]; int n,m,t[MAXN],sgt[2][MAXN<<2]; ll dp[MAXN],rs=1e18; vector<int> v; priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq; multiset<pair<int,int>> ms[2][MAXN]; bool check(int i, int j){ if(a[i].t>=a[j].t) return a[i].r-a[i].t+1>=a[j].l-a[j].t; return a[i].r+a[i].t+1>=a[j].l+a[j].t; } void build(int id, int l, int r, int pos, int val){ if(pos<l||r<pos) return; if(l==r){ ms[0][l].ins(a[val].l-a[val].t,val), ms[1][l].ins(a[val].l+a[val].t,val); sgt[0][id]=ms[0][l].begin()->fi, sgt[1][id]=ms[1][l].begin()->fi; return; } int mid=(l+r)>>1; if(pos<=mid) build(id<<1,l,mid,pos,val); else build(id<<1|1,mid+1,r,pos,val); sgt[0][id]=min(sgt[0][id<<1],sgt[0][id<<1|1]); sgt[1][id]=min(sgt[1][id<<1],sgt[1][id<<1|1]); } void update(bool type, int id, int l, int r, int u, int v, ll val, int checkval){ if(v<l||r<u||sgt[type][id]>checkval) return; if(l==r){ while(!ms[type][l].empty()){ pair<int,int> p = *ms[type][l].begin(); if(checkval>=p.fi){ if(dp[p.se]>val+a[p.se].cost) dp[p.se]=val+a[p.se].cost, pq.ins(dp[p.se],p.se); }else break; ms[type][l].erase(ms[type][l].begin()); } if(ms[type][l].empty()) sgt[type][id]=2e9; else sgt[type][id]=ms[type][l].begin()->fi; return; } int mid=(l+r)>>1; update(type,id<<1,l,mid,u,v,val,checkval); update(type,id<<1|1,mid+1,r,u,v,val,checkval); sgt[type][id]=min(sgt[type][id<<1],sgt[type][id<<1|1]); } int main() { tt; if(fopen((NAME + ".INP").c_str(), "r")) fo; memset(dp,0x3f,sizeof(dp)); memset(sgt,0x3f,sizeof(sgt)); cin >> n >> m; for(int i = 1; i<=m; ++i){ cin >> a[i].t >> a[i].l >> a[i].r >> a[i].cost; if(a[i].l==1) dp[i]=a[i].cost, pq.ins(a[i].cost,i); v.pb(a[i].t); } sort(v.begin(),v.end()); v.resize(unique(v.begin(),v.end())-v.begin()); for(int i = 1; i<=m; ++i){ t[i]=lb(v.begin(),v.end(),a[i].t)-v.begin()+1; build(1,1,sz(v),t[i],i); } while(!pq.empty()){ pair<ll,int> top=pq.top(); pq.pop(); if(top.fi>dp[top.se]) continue; if(a[top.se].r==n) rs=min(rs,top.fi); update(0,1,1,sz(v),1,t[top.se],top.fi,a[top.se].r-a[top.se].t+1); update(1,1,1,sz(v),t[top.se]+1,sz(v),top.fi,a[top.se].r+a[top.se].t+1); } cout << (rs>=1e18 ? -1 : rs); }

Compilation message (stderr)

treatment.cpp: In function 'int main()':
treatment.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
treatment.cpp:69:45: note: in expansion of macro 'fo'
   69 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
treatment.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
treatment.cpp:69:45: note: in expansion of macro 'fo'
   69 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...