QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#153250 | #7105. Pixel Art | PhantomThreshold | AC ✓ | 331ms | 36736kb | C++20 | 3.8kb | 2023-08-29 19:21:58 | 2023-09-04 04:30:23 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
const int maxn = 1010000;
int n,m,K;
struct node
{
int sig,r,c,fi;
}o[maxn<<1]; int on;
inline bool cmp(const node &k1,const node &k2){ return k1.r==k2.r? k1.c<k2.c : k1.r<k2.r; }
vector< tuple<int,int,int> >V[maxn];
int fa[maxn],fn,cnt,num;
int findfa(const int x){ return fa[x]==x?x:fa[x]=findfa(fa[x]); }
void merge(int x,int y)
{
int f1=findfa(x),f2=findfa(y);
if(f1!=f2) fa[f1]=f2,cnt--;
}
set< pair<int,int> >S;
int intersect( const tuple<int,int,int>&u, const tuple<int,int,int>&v )
{
if(get<0>(u) <= get<0>(v)) return get<1>(u) >= get<0>(v);
else return get<1>(v) >= get<0>(u);
}
signed main()
{
// freopen("tmp.in","r",stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
int Tcase; cin>>Tcase;
while(Tcase--)
{
cin>>n>>m>>K;
for(int r=0;r<=n;r++)
{
vector< tuple<int,int,int> >_;
V[r].swap(_);
}
on=0;S.clear();
for(int i=1;i<=K;i++)
{
int r1,c1,r2,c2; cin>>r1>>c1>>r2>>c2;
if(c1==c2)
{
o[++on]=(node){1,r1,c1,0};
o[++on]=(node){-1,r2+1,c1,0};
}
else
{
V[r1].emplace_back(c1,c2,0);
}
}
sort(o+1,o+on+1,cmp);
for(int r=1;r<=n;r++) sort(V[r].begin(),V[r].end());
fn=cnt=num=0;
int nowo=1;
for(int r=1;r<=n;r++)
{
map<int,int>mp;
{
int tmpo=nowo;
int lasv=0,siz=V[r-1].size();
while(tmpo<=on && o[tmpo].r==r)
{
if(o[tmpo].sig==1)
{
int fi= ++fn; fa[fi]=fi; ++cnt;
o[tmpo].fi= fi;
auto it=S.lower_bound( make_pair(o[tmpo].c,0) );
if(it!=S.end() && it->first==o[tmpo].c)
{
mp[ o[tmpo].c ]=1;
merge( fi, it->second );
}
else
{
S.insert( make_pair(o[tmpo].c,fi) );
}
while(lasv<siz && get<1>(V[r-1][lasv]) < o[tmpo].c ) lasv++;
if(lasv<siz && get<0>(V[r-1][lasv])<= o[tmpo].c )
merge( get<2>(V[r-1][lasv]), fi );
}
tmpo++;
}
}
{
int lasv=0,siz=V[r-1].size();
for(int i=0,szi=(int)V[r].size();i<szi;i++)
{
auto &[c1,c2,fi] = V[r][i];
num+=c2-c1+1;
if(fi==0)
{
fi=++fn; fa[fi]=fi; ++cnt;
}
while(lasv<siz && get<1>(V[r-1][lasv])< c1 )
lasv++;
while(lasv<siz && intersect(V[r][i], V[r-1][lasv]))
{
merge(fi, get<2>(V[r-1][lasv]) );
lasv++;
}
if(lasv>0) lasv--;
if(i>0 && get<1>(V[r][i-1])+1==c1)
merge(fi, get<2>(V[r][i-1]) );
auto it=S.lower_bound( make_pair(c1,0) );
while( it!=S.end() && it->first <= c2 )
{
merge(fi, it->second);
it++;
}
}
}
{
int tmpo=nowo;
while(nowo<=on && o[nowo].r==r)
{
if(o[nowo].sig==-1 && mp.count(o[nowo].c)==0)
{
auto it=S.lower_bound( make_pair(o[nowo].c,0) );
S.erase(it);
}
nowo++;
}
while(tmpo<=on && o[tmpo].r==r)
{
if(o[tmpo].sig==1)
{
int c=o[tmpo].c, fi=o[tmpo].fi;
auto it=S.lower_bound( make_pair(c-1,0) );
if( it->first == c-1 )
merge( it->second,fi );
it=S.lower_bound( make_pair(c+1,0) );
if( it->first == c+1 )
merge( it->second,fi );
}
tmpo++;
}
}
{
for(int i=0,szi=(int)V[r].size();i<szi;i++)
{
auto &[c1,c2,fi] = V[r][i];
auto it=S.lower_bound( make_pair(c1-1,0) );
if( it!=S.end() && it->first ==c1-1 )
{
merge(fi, it->second);
}
it=S.lower_bound( make_pair(c2+1,0) );
if( it!=S.end() && it->first ==c2+1 )
{
merge(fi, it->second);
}
}
}
num+= S.size();
cout<<num<<' '<<cnt<<'\n';
}
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 28232kb
input:
3 2 5 2 1 1 1 2 2 3 2 5 2 5 2 1 1 1 3 2 3 2 5 3 3 3 1 1 1 2 3 1 3 2 1 3 2 3
output:
2 1 5 2 3 1 6 1 3 1 4 1 6 2
result:
ok 7 lines
Test #2:
score: 0
Accepted
time: 331ms
memory: 36736kb
input:
2130 2 5 2 1 1 1 2 2 3 2 5 2 5 2 1 1 1 3 2 3 2 5 3 3 3 1 1 1 2 3 1 3 2 1 3 2 3 3 100 51 1 2 2 2 1 4 2 4 1 6 2 6 1 8 2 8 1 10 2 10 1 12 2 12 1 14 2 14 1 16 2 16 1 18 2 18 1 20 2 20 1 22 2 22 1 24 2 24 1 26 2 26 1 28 2 28 1 30 2 30 1 32 2 32 1 34 2 34 1 36 2 36 1 38 2 38 1 40 2 40 1 42 2 42 1 44 2 44 ...
output:
2 1 5 2 3 1 6 1 3 1 4 1 6 2 50 50 100 50 200 1 50 50 150 1 200 1 2 1 4 1 6 1 8 1 10 1 12 1 14 1 16 1 18 1 20 1 22 1 24 1 26 1 28 1 30 1 32 1 34 1 36 1 38 1 40 1 42 1 44 1 46 1 48 1 50 1 52 1 54 1 56 1 58 1 60 1 62 1 64 1 66 1 68 1 70 1 72 1 74 1 76 1 78 1 80 1 82 1 84 1 86 1 88 1 90 1 92 1 94 1 96 1...
result:
ok 355756 lines
Extra Test:
score: 0
Extra Test Passed