제출 #754999

#제출 시각아이디문제언어결과실행 시간메모리
754999DJeniUpAliens (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,r; }d[2*N]; bool mcp(D d1, D d2){ if(d1.l!=d2.l)return d1.l<d2.l; return d1.r>d2.r; } ll T(ll x,ll y){ if(nr[x]<nl[y] || x==0)return 0; return (nr[x]-nl[y]+1)*(nr[x]-nl[y]+1); } 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)-T(pr[x],x); } 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,y}; } sort(d+1,d+1+h,mcp); ll x=0; for(int i=1;i<=h;i++){ if(x<d[i].r){ p++; nl[p]=d[i].l; nr[p]=d[i].r; } x=max(x,d[i].r); } ll res=0; for(int i=1;i<=p;i++){ //cout<<i<<" "<< res+=(nr[i]-nl[i]+1)*(nr[i]-nl[i]+1)-T(i-1,i); 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...