Submission #782095

#TimeUsernameProblemLanguageResultExecution timeMemory
782095FEDIKUSRadio Towers (IOI22_towers)C++17
0 / 100
571 ms25112 KiB
#include "towers.h" #include <bits/stdc++.h> using namespace std; using mim = pair<pair<int,int>,int>; const int maxn=1e5+10; const int logg=18; int n; int h[maxn]; multiset<int> res; mim sparse[logg][maxn]; int klk; int pref[maxn]; int uniq[maxn]; mim comb(mim &a,mim &b){ mim ret=a; ret.first=max(ret.first,b.first); ret.second=min(ret.second,b.second); return ret; } mim qry(int l,int r){ mim ret={{h[l],l},h[l]}; for(int i=logg-1;i>=0;i--){ if(r-(1<<i)+1>=l){ ret=comb(ret,sparse[i][r]); r-=(1<<i); } } return ret; } void resi(int l,int r,multiset<int> &ret,int naj=2e9+10){ if(r<l) return; auto temp=qry(l,r); pair<int,int> maxi=temp.first; int mini=temp.second; multiset<int> levi; multiset<int> desni; resi(l,maxi.second-1,levi,maxi.first); resi(maxi.second+1,r,desni,maxi.first); if(levi.size()>desni.size()) swap(levi,desni); for(int i:desni) levi.emplace(i); if(!levi.empty()){ auto najm=levi.begin(); int d=naj-mini; if(*najm>d){ levi.erase(najm); levi.emplace(d); } }else{ levi.emplace(naj-mini); } swap(ret,levi); } void init(int _n, vector<int> _h) { n=_n; for(int i=0;i<n;i++) h[i]=_h[i]; for(int i=0;i<logg;i++){ for(int j=0;j<n;j++){ if(i==0) sparse[i][j]={{h[j],j},h[j]}; else if(j-(1<<(i-1))>=0) sparse[i][j]=comb(sparse[i-1][j],sparse[i-1][j-(1<<(i-1))]); else sparse[i][j]=sparse[i-1][j]; } } resi(0,n-1,res); klk=0; for(int i:res) uniq[klk++]=i; klk=unique(uniq,uniq+klk)-uniq; int tren=0; for(int i:res){ if(uniq[tren]!=i){ tren++; pref[tren]=pref[tren-1]; } pref[tren]++; } } int max_towers(int l, int r, int d) { int koji=upper_bound(uniq,uniq+klk,d)-uniq-1; if(koji==-1) return 0; return pref[koji]; }
#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...