Submission #754997

#TimeUsernameProblemLanguageResultExecution timeMemory
754997DJeniUpAliens (IOI16_aliens)C++17
0 / 100
1 ms340 KiB
#include "aliens.h" #include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<ll,ll>pairll; #define N 100007 #define fr first #define sc second ll h,nl[2*N],nr[2*N],pr[2*N],nx[2*N],p; struct D{ ll l,tp; }d[2*N]; bool mcp(D d1, D d2){ if(d1.l!=d2.l)return d1.l<d2.l; return d1.tp>d2.tp; } ll S(ll x,ll y){ return (nr[y]-nl[x]+1)*(nr[y]-nl[x]+1)-(nr[y]-nl[y]+1)*(nr[y]-nl[y]+1)-(nr[x]-nl[x]+1)*(nr[x]-nl[x]+1); } priority_queue<pairll,vector<pairll>, greater<pairll> >q; long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) { for(int i=0;i<n;i++){ ll x=0; ll y=0; x=min(r[i],c[i]); y=max(r[i],c[i]); h++; d[h]={x,1}; h++; d[h]={y,-1}; } sort(d+1,d+1+h,mcp); ll x=0; for(int i=1;i<=h;i++){ if(x==0){ p++; nl[p]=d[i].l; } nr[p]=d[i].l; x+=d[i].tp; } ll res=0; for(int i=1;i<=p;i++){ res+=(nr[i]-nl[i]+1)*(nr[i]-nl[i]+1); pr[i]=i-1; nx[i]=i+1; if(i!=1)q.push({S(i-1,i),i-1}); } for(int i=1;i<=p-k;i++){ while(q.size()>0 && q.top().fr!=S(q.top().sc,nx[q.top().sc]))q.pop(); res+=q.top().fr; ll m1=q.top().sc; nr[m1]=nr[nx[m1]]; nx[m1]=nx[nx[m1]]; if(nx[m1]!=0 && nx[m1]!=p+1){ q.push({S(m1,nx[m1]),m1}); } if(pr[m1]!=0){ q.push({S(pr[m1],m1),pr[m1]}); } } return res; }
#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...