Submission #219404

#TimeUsernameProblemLanguageResultExecution timeMemory
219404ho94949Treatment Project (JOI20_treatment)C++17
100 / 100
246 ms34384 KiB
#include <bits/stdc++.h> using namespace std; const int MAXM = 131072; int N, M; int T[MAXM], L[MAXM], R[MAXM], C[MAXM]; int XL[MAXM], YL[MAXM], XR[MAXM], YR[MAXM]; bool vis[MAXM]; vector<pair<int, int> > idx[2*MAXM]; int ptr[2*MAXM]; bool in[MAXM]; void build(vector<tuple<int, int, int> > Vxyi) { for(auto [x, y, i]: Vxyi) { idx[x+MAXM].emplace_back(y, i); in[i] = true; } for(int i=MAXM; i<2*MAXM; ++i) sort(idx[i].begin(), idx[i].end()); for(int i=MAXM-1; i>=1; --i) { idx[i].resize(idx[2*i].size()+idx[2*i+1].size()); merge(idx[2*i].begin(), idx[2*i].end(), idx[2*i+1].begin(), idx[2*i+1].end(), idx[i].begin()); } } vector<int> popc(int x, int y) { vector<int> ret; int f = MAXM, t = x+MAXM; while(f<=t&&t) { if(t%2==0 || f==t) { while(ptr[t] < (int)idx[t].size()) { auto [val, iv] = idx[t][ptr[t]]; if(val>y) break; if(in[iv]) ret.push_back(iv), in[iv]=false; ++ptr[t]; } --t; } f/=2; t/=2; } return ret; } int main() { scanf("%d%d", &N, &M); vector<int> x, y; for(int i=0; i<M; ++i) { scanf("%d%d%d%d", T+i, L+i, R+i, C+i); --L[i]; //L[i] = 0, R[i] = N covers whole XL[i] = L[i]-T[i], YL[i] = L[i]+T[i]; XR[i] = R[i]-T[i], YR[i] = R[i]+T[i]; x.push_back(XL[i]); y.push_back(YL[i]); } sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end()); sort(y.begin(), y.end()); y.erase(unique(y.begin(), y.end()), y.end()); for(int i=0; i<M; ++i) { XL[i] = lower_bound(x.begin(), x.end(), XL[i]) - x.begin(); XR[i] = upper_bound(x.begin(), x.end(), XR[i]) - x.begin() - 1; YL[i] = lower_bound(y.begin(), y.end(), YL[i]) - y.begin(); YR[i] = upper_bound(y.begin(), y.end(), YR[i]) - y.begin() - 1; } using pli = pair<long long, int>; priority_queue<pli, vector<pli>, greater<pli>> Q; vector<tuple<int, int, int> > Vxyi; for(int i=0; i<M; ++i) if(L[i] == 0) vis[i] = true, Q.emplace((long long)C[i], i); else Vxyi.emplace_back(XL[i], YL[i], i); build(Vxyi); while(!Q.empty()) { auto [cost, idx] = Q.top(); Q.pop(); if(R[idx] == N) return printf("%lld\n", cost), 0; vector<int> idxs = popc(XR[idx], YR[idx]); for(auto i: idxs) { vis[i] = true; Q.emplace(cost+C[i], i); } } puts("-1"); }

Compilation message (stderr)

treatment.cpp: In function 'int main()':
treatment.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &M);
     ~~~~~^~~~~~~~~~~~~~~~
treatment.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d%d", T+i, L+i, R+i, C+i);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...