제출 #1363495

#제출 시각아이디문제언어결과실행 시간메모리
1363495vivkostovRectangles (IOI19_rect)C++20
10 / 100
4905 ms696252 KiB
#include "rect.h"
#include "bits/stdc++.h"
using namespace std;
struct cell
{
    int i,j,st;
};
bool cmp(cell a1,cell a2)
{
    return a1.st<a2.st;
}
int a[3005][3005],n,m,in[10005],cur=1,miv[50000000],mav[50000000],mih[50000000],mah[50000000],omiv,omav,omih,omah,vmi,vma,xmi,xma,ql,qr,ql1,qr1;
map<int,int>mv[3005],mh[3005];
map<long long int,int>otg;
cell c[10000000];
inline void convert(long long int i1,long long int j1,long long int i2,long long int j2)
{
    long long int nn=n,mm=m;
    otg[(i1*mm+j1)*(nn*mm)+i2*mm+j2]=1;
}
inline void build(int l,int r,int h)
{
    in[h]=cur;
    cur+=10000;
    if(l==r)return;
    int mid=(l+r)/2;
    build(l,mid,h*2);
    build(mid+1,r,h*2+1);
}
inline void update2(int l,int r,int q,int h,int con)
{
    int cur=h+con,le=h*2+con,re=h*2+1+con;
    if(l==r)
    {
        miv[cur]=vmi;
        mav[cur]=vma;
        mih[cur]=xmi;
        mah[cur]=xma;
        return;
    }
    int mid=(l+r)/2;
    if(mid>=q)update2(l,mid,q,h*2,con);
    else update2(mid+1,r,q,h*2+1,con);
    mav[cur]=max(mav[le],mav[re]);
    miv[cur]=min(miv[le],miv[re]);
    mah[cur]=max(mah[le],mah[re]);
    mih[cur]=min(mih[le],mih[re]);
}
inline void update1(int l,int r,int q1,int q2,int h)
{
    update2(1,m,q2,1,in[h]);

    if(l==r)
    {
        return;
    }
    int mid=(l+r)/2;
    if(mid>=q1)update1(l,mid,q1,q2,h*2);
    else update1(mid+1,r,q1,q2,h*2+1);
}
inline void query2(int l,int r,int h,int con)
{
    if(l>qr||r<ql)return;
    int cur=h+con;
    if(l>=ql&&r<=qr)
    {
        omiv=min(omiv,miv[cur]);
        omav=max(omav,mav[cur]);
        omih=min(omih,mih[cur]);
        omah=max(omah,mah[cur]);
        return;
    }
    int mid=(l+r)/2;
    query2(l,mid,h*2,con);
    query2(mid+1,r,h*2+1,con);
}
inline void query1(int l,int r,int h)
{
    if(l>qr1||r<ql1)return;

    if(l>=ql1&&r<=qr1)
    {
        query2(1,m,1,in[h]);
        return;
    }
    int mid=(l+r)/2;
    query1(l,mid,h*2);
    query1(mid+1,r,h*2+1);
}
inline void resh(int i,int j,int st)
{
    //cout<<i<<" "<<j<<" "<<st<<endl;
    auto h=mh[i].upper_bound(j);
    int cmah=h->first;
    h--;
    int cmih=h->first;
    h=mv[j].upper_bound(i);
    int cmav=h->first;
    h--;
    int cmiv=h->first;
    cmiv++;
    cmih++;
    cmav--;
    cmah--;
    if(i==5&&j==3)
    {
        /*cout<<endl<<endl;
        cout<<"--------"<<endl;
        cout<<cmiv<<" "<<cmav<<" "<<cmih<<" "<<cmah<<endl<<endl;*/
    }
    xmi=ql=cmih;
    xma=qr=cmah;
    vmi=ql1=cmiv;
    vma=qr1=cmav;
    update1(1,n,i,j,1);
    if(cmiv>1&&cmav<n&&cmih>1&&cmah<m)
    {
        omiv=1e9;
        omih=1e9;
        omav=0;
        omah=0;
        //cout<<"!"<<endl;
        query1(1,n,1);
        if(i==5&&j==3)
        {
            //cout<<omiv<<" "<<omav<<" "<<omih<<" "<<omah<<endl<<endl<<endl;
        }
        if(cmih==omih&&cmah==omah&&cmiv==omiv&&cmav==omav)
        {
            /*cout<<i<<" "<<j<<" "<<st<<endl;
            cout<<cmiv<<" "<<cmav<<" "<<cmih<<" "<<cmah<<endl;
            cout<<omiv<<" "<<omav<<" "<<omih<<" "<<omah<<endl;
            cout<<"???"<<endl;*/
            convert(cmiv,cmih,cmav,cmah);
        }
    }
}
long long int count_rectangles(vector<vector<int> > A)
{
    n=A.size();
    m=A[0].size();
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            a[i+1][j+1]=A[i][j];
            c[i*m+j+1].i=i+1;
            c[i*m+j+1].j=j+1;
            c[i*m+j+1].st=a[i+1][j+1];
        }
    }
    build(1,n,1);
    sort(c+1,c+n*m+1,cmp);
    //cout<<endl<<endl;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=m+1;j++)
        {
            mh[i][j]=1;
        }
    }
    for(int j=1;j<=m;j++)
    {
        for(int i=0;i<=n+1;i++)
        {
            mv[j][i]=1;
        }
    }
    int to=1;
    for(int i=1;i<=n*m;i++)
    {
        while(to<=n*m&&c[to].st==c[i].st)
        {
            mv[c[to].j].erase(c[to].i);
            mh[c[to].i].erase(c[to].j);
            to++;
        }
        resh(c[i].i,c[i].j,c[i].st);
    }
	return otg.size();
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…