Submission #249611

#TimeUsernameProblemLanguageResultExecution timeMemory
249611LittleFlowers__Sky Walking (IOI19_walk)C++17
33 / 100
1984 ms100248 KiB
#include <bits/stdc++.h> using namespace std; #define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;}) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int rnd(int l,int r){return l+rng()%(r-l+1);} #define fasty ios_base::sync_with_stdio(0),cin.tie(0); #define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a) #define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a) #define forv(a,b) for(auto&a:b) #define fi first #define se second #define pb push_back #define ii pair<int,int> #define mt make_tuple #define all(a) a.begin(),a.end() #define reset(f, x) memset(f, x, sizeof(f)) #define gg exit(0); const long long INF=1e18+10; const int N=100010; long long f[N]; vector<int> val; multiset<long long> up[N],dw[N]; void upd_u(int i,long long j,int t){ i=lower_bound(all(val),i)-val.begin()+1; for(;i;i-=i&-i){ if(t) up[i].insert(j); else up[i].erase(up[i].find(j)); } } void upd_d(int i,long long j,int t){ i=lower_bound(all(val),i)-val.begin()+1; for(;i<=val.size();i+=i&-i){ if(t) dw[i].insert(j); else dw[i].erase(dw[i].find(j)); } } long long que_u(int i){ i=lower_bound(all(val),i)-val.begin()+1; long long ret=INF; for(;i<=val.size();i+=i&-i) if(up[i].size()) ret=min(ret,*up[i].begin()); return ret; } long long que_d(int i){ i=lower_bound(all(val),i)-val.begin()+1; long long ret=INF; for(;i;i-=i&-i) if(dw[i].size()) ret=min(ret,*dw[i].begin()); return ret; } long long min_distance(vector<int> x,vector<int> h,vector<int> l,vector<int> r,vector<int> y,int s,int g){ val=y, val.pb(0), sort(all(val)), val.erase(unique(all(val)),val.end()); vector<ii> q; forinc(i,1,l.size()){ q.push_back({l[i-1],-i}); q.push_back({r[i-1],i}); } q.push_back({0,l.size()+1}); q.push_back({0,-l.size()-1}); sort(all(q)); y.emplace_back(); x.push_back(x[0]); l.push_back(0); r.push_back(0); long long ret=INF; forv(i,q){ if(i.se<0){ i.se=-i.se; i.se--; f[i.se]=min(x[l[i.se]]+y[i.se]+que_d(y[i.se]),x[l[i.se]]-y[i.se]+que_u(y[i.se])); if(i.se==l.size()-1) f[i.se]=0; upd_d(y[i.se],f[i.se]-x[l[i.se]]-y[i.se],1); upd_u(y[i.se],f[i.se]-x[l[i.se]]+y[i.se],1); if(r[i.se]==x.size()-2) ret=min(ret,f[i.se]+x[r[i.se]]-x[l[i.se]]+y[i.se]); } else{ i.se--; upd_d(y[i.se],f[i.se]-x[l[i.se]]-y[i.se],0); upd_u(y[i.se],f[i.se]-x[l[i.se]]+y[i.se],0); } } return ret==INF ? -1 : ret; }

Compilation message (stderr)

walk.cpp: In function 'void upd_d(int, long long int, int)':
walk.cpp:35:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(;i<=val.size();i+=i&-i){
          ~^~~~~~~~~~~~
walk.cpp: In function 'long long int que_u(int)':
walk.cpp:43:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(;i<=val.size();i+=i&-i) if(up[i].size())
          ~^~~~~~~~~~~~
walk.cpp: In function 'long long int min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:77:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(i.se==l.size()-1) f[i.se]=0;
                ~~~~^~~~~~~~~~~~
walk.cpp:80:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(r[i.se]==x.size()-2)
#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...