제출 #675055

#제출 시각아이디문제언어결과실행 시간메모리
675055numberesAliens (IOI16_aliens)C++17
100 / 100
206 ms18020 KiB
/** * @date 2022-12-26 10:42:24 * @author numberes * 煮不在乎.RAmen! */ #include<bits/stdc++.h> #include "aliens.h" #define fi first #define se second #define mp make_pair #define pb push_back #define pii pair<int,int> #define ll long long using namespace std; ll g[1000005]; int t[1000005],dq[1000005],dl,dr; int n,m,k; int l[1000005],r[1000005],p[1000005]; struct line{ ll k,b; }li[1000005]; long double itsect(int a,int b){ return (long double)(li[b].b-li[a].b)/(li[a].k-li[b].k); } void calc(ll c){ memset(g,0,sizeof(g));memset(t,0,sizeof(t)); dl=dr=1;dq[1]=1; li[1].k=-2*(ll)(l[1]-1); li[1].b=g[1]+(ll)(l[1]-1)*(ll)(l[1]-1)+c; for(int i=2;i<=n+1;i++){ while(dl+1<=dr && itsect(dq[dl],dq[dl+1])<r[i-1]) ++dl; g[i]=li[dq[dl]].k*r[i-1]+li[dq[dl]].b+(ll)r[i-1]*(ll)r[i-1]; t[i]=t[dq[dl]]+1; li[i].k=-2*(ll)(l[i]-1); li[i].b=g[i]+(ll)(l[i]-1)*(ll)(l[i]-1)-(ll)max(0,r[i-1]-l[i]+1)* (ll)max(0,r[i-1]-l[i]+1)+c; while(dl+1<=dr && itsect(i,dq[dr])<itsect(dq[dr],dq[dr-1])) dr--; dq[++dr]=i; } } ll solve(){ ll lb=-1,ub=2e12; while(lb+1<=ub-1){ ll mid=(lb+ub)>>1; calc(mid); if(t[n+1]>k) lb=mid; else ub=mid; } calc(ub); return g[n+1]-k*ub; } ll take_photos(int _n,int _m,int _k,vector<int> _r,vector<int> _c){ n=_n;m=_m;k=_k; for(int i=0;i<n;i++){ int le=min(_r[i],_c[i]),ri=max(_r[i],_c[i]); p[i]=i;_r[i]=le;_c[i]=ri; } sort(p,p+n,[&](int a,int b){return (_r[a]!=_r[b]?_r[a]<_r[b]:_c[a]>_c[b]);}); int tmp=0,mr=-1; for(int i=0;i<n;i++) if(_c[p[i]]>mr){ l[++tmp]=_r[p[i]]; r[tmp]=_c[p[i]]; mr=_c[p[i]]; } n=tmp; return solve(); }
#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...