QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#158085 | #7105. Pixel Art | ucup-team1477# | AC ✓ | 111ms | 22328kb | C++14 | 3.2kb | 2023-09-02 16:11:46 | 2023-09-04 04:30:30 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
int n=0,f=1,ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
n=n*10+ch-'0';
ch=getchar();
}
return n*f;
}
int r1[100005],c1[100005],r2[100005],c2[100005];
int xl[100005],cnt;
int now[100005];
int fa[200005];
vector<int>cx[100005],xs[100005],hx[200005];
int findf(int n)
{
if(fa[n]==n)return n;
return fa[n]=findf(fa[n]);
}
bool bi(int x,int y)
{
return c1[x]<c1[y];
}
int lt=0;
void merge(int x,int y)
{
x=findf(x);
y=findf(y);
if(x==y)return;
fa[x]=y;
lt--;
}
signed main()
{
int t,n,m,k;
t=read();
for(int greg=1;greg<=t;greg++)
{
n=read();
m=read();
k=read();
for(int i=1;i<=n+1;i++)
{
cx[i].clear();
xs[i].clear();
hx[i].clear();
}
for(int i=1;i<=k;i++)
{
r1[i]=read();
c1[i]=read();
r2[i]=read();
c2[i]=read();
fa[i]=i;
if(c1[i]==c2[i])
{
cx[r1[i]].push_back(i);
xs[r2[i]+1].push_back(i);
}
else
{
hx[r1[i]].push_back(i);
}
}
for(int i=1;i<=n;i++)sort(hx[i].begin(),hx[i].end(),bi);
long long zs=0,het=0;
lt=0;
for(int i=1;i<=n;i++)
{
cnt=0;
for(int j=0;j<xs[i].size();j++)
{
xl[++cnt]=xs[i][j];
}
sort(xl+1,xl+cnt+1,bi);
int gre=1;
for(int j=0;j<hx[i].size();j++)
{
lt++;
int l=c1[hx[i][j]],r=c2[hx[i][j]];
while(gre<=cnt&&c1[xl[gre]]<l)gre++;
while(gre<=cnt&&c1[xl[gre]]<=r)
{
merge(hx[i][j],xl[gre]);
gre++;
}
het+=r-l+1;
if(j+1<hx[i].size()&&c1[hx[i][j+1]]==c2[hx[i][j]]+1)
{
merge(hx[i][j],hx[i][j+1]);
}
}
cnt=0;
for(int j=0;j<cx[i].size();j++)
{
if(now[c1[cx[i][j]]]!=0)
{
merge(cx[i][j],now[c1[cx[i][j]]]);
}
}
for(int j=0;j<xs[i].size();j++)
{
now[c1[xs[i][j]]]=0;
zs--;
}
for(int j=0;j<cx[i].size();j++)
{
xl[++cnt]=cx[i][j];
lt++;
now[c1[cx[i][j]]]=cx[i][j];
int tid=cx[i][j],sth=c1[cx[i][j]];
if(sth-1>=1&&now[sth-1]!=0)
{
merge(tid,now[sth-1]);
}
if(sth+1<=m&&now[sth+1]!=0)
{
merge(tid,now[sth+1]);
}
zs++;
}
sort(xl+1,xl+cnt+1,bi);
het+=zs;
if(i>1)
{
gre=1;
for(int j=0;j<hx[i-1].size();j++)
{
int l=c1[hx[i-1][j]],r=c2[hx[i-1][j]];
while(gre<=cnt&&c1[xl[gre]]<l)gre++;
while(gre<=cnt&&c1[xl[gre]]<=r)
{
merge(hx[i-1][j],xl[gre]);
gre++;
}
}
}
for(int j=0;j<hx[i].size();j++)
{
int l=c1[hx[i][j]],r=c2[hx[i][j]];
if(l>1&&now[l-1]!=0)merge(now[l-1],hx[i][j]);
if(r<m&&now[r+1]!=0)merge(now[r+1],hx[i][j]);
}
if(i>1)
{
int now=0;
for(int j=0;j<hx[i].size();j++)
{
while(now<hx[i-1].size()&&c2[hx[i-1][now]]<c1[hx[i][j]])now++;
while(now<hx[i-1].size()&&c2[hx[i-1][now]]<=c2[hx[i][j]])
{
merge(hx[i-1][now],hx[i][j]);
now++;
}
if(now<hx[i-1].size()&&c1[hx[i-1][now]]<=c2[hx[i][j]])
{
merge(hx[i-1][now],hx[i][j]);
}
}
}
printf("%lld %d\n",het,lt);
}
for(int i=1;i<=k;i++)now[c1[i]]=0;
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 15212kb
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: 111ms
memory: 22328kb
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