QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#161197 | #7105. Pixel Art | ucup-team1732# | TL | 2ms | 11696kb | C++14 | 3.4kb | 2023-09-02 22:57:25 | 2023-09-02 22:57:26 |
Judging History
answer
// created: Sep/02/2023 22:19:28
#include<cstdio>
#include<vector>
#include<set>
#define F(i,l,r) for(int i=l,i##_end=r;i<i##_end;++i)
using namespace std;
template<typename T>void readmain(T &x)
{
bool neg=false;
unsigned int c=getchar();
for(;(c^48)>9;c=getchar())if(c=='-')neg=true;
for(x=0;(c^48)<10;c=getchar())x=(x<<3)+(x<<1)+(c^48);
if(neg)x=-x;
}
template<typename T>T& read(T &x){readmain(x);return x;}
template<typename T,typename ...Tr>void read(T &x,Tr&... r){readmain(x);read(r...);}
constexpr int N=1e5+5,INF=0x3f3f3f3f;
int tt,n,m,k,x[N],l[N],r[N],f[N];
int find(int u){return f[u]==u?u:f[u]=find(f[u]);}
vector<int> a[N],b0[N],b1[N];
set<pair<int,int>> s,t;
int main()
{
read(tt);
while(tt--)
{
read(n,m,k);
F(i,0,k)
{
int r1,c1,r2,c2;read(r1,c1,r2,c2);--r1,--c1,--r2,--c2;
if(r1==r2)
{
x[i]=r1;
l[i]=c1,r[i]=c2+1;
a[r1].emplace_back(i);
}
else
{
x[i]=c1;
l[i]=r1,r[i]=r2+1;
b0[l[i]].emplace_back(i);
b1[r[i]].emplace_back(i);
}
f[i]=i;
}
int ans=0;
long long sum=0,cur=0;
s.clear();
F(i,0,n)
{
cur+=b0[i].size()-b1[i].size();
sum+=cur;
ans+=(int)b0[i].size()+(int)a[i].size();
for(int j:a[i])sum+=r[j]-l[j];
if(i)
{
for(int j:a[i])
{
auto il=t.lower_bound({l[j],-INF});
auto ir=t.lower_bound({r[j],-INF});
for(auto it=il;it!=ir;++it)
{
int v=it->second;
if(find(j)!=find(v))--ans,f[find(j)]=find(v);
}
}
}
for(int j:b0[i])
{
auto it=t.lower_bound({x[j],-INF});
if(it!=t.end())
{
int v=it->second;
if(x[j]==x[v]&&find(j)!=find(v))--ans,f[find(j)]=find(v);
}
}
for(int j:b0[i])t.emplace(x[j],j);
for(int j:b1[i])t.erase({x[j],j});
for(int j:a[i])
{
auto it=t.lower_bound({l[j],0});
if(it!=t.begin())
{
int v=prev(it)->second;
if(x[v]==l[j]-1&&find(j)!=find(v))--ans,f[find(j)]=find(v);
}
if(it!=t.end())
{
int v=it->second;
if(x[v]==r[j]&&find(j)!=find(v))--ans,f[find(j)]=find(v);
}
}
for(int j:b0[i])
{
auto it=t.find({x[j],j});
if(it!=t.begin())
{
int v=prev(it)->second;
if(x[v]==x[j]-1&&find(j)!=find(v))--ans,f[find(j)]=find(v);
}
if(next(it)!=t.end())
{
int v=next(it)->second;
if(x[v]==x[j]+1&&find(j)!=find(v))--ans,f[find(j)]=find(v);
}
}
if(!a[i].empty())for(auto it=a[i].begin();next(it)!=a[i].end();++it)
{
if(r[*it]==l[*next(it)])
{
int u=*it,y=*next(it);
if(find(u)!=find(y))--ans,f[find(u)]=find(y);
}
}
if(i)
{
for(int j:b0[i])
{
auto it=s.lower_bound({x[j],INF});
if(it!=s.begin())
{
--it;
int v=it->second;
if(x[j]<r[v]&&find(j)!=find(v))--ans,f[find(j)]=find(v);
}
}
for(int j:a[i])
{
auto it=s.lower_bound({l[j],INF});
if(it!=s.begin())
{
int v=prev(it)->second;
if(l[j]<r[v]&&find(j)!=find(v))--ans,f[find(j)]=find(v);
}
}
for(int j:a[i-1])
{
auto it=s.lower_bound({l[j],INF});
if(it!=s.begin())
{
int v=prev(it)->second;
if(l[j]<r[v]&&find(j)!=find(v))--ans,f[find(j)]=find(v);
}
}
}
s.clear();
for(int j:a[i])s.emplace(l[j],j);
printf("%lld %d\n",sum,ans);
}
F(i,0,n)a[i].clear();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 11696kb
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: -100
Time Limit Exceeded
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 51 51 102 51 202 2 101 51 252 52 302 52 103 3 256 54 308 55 310 56 312 57 314 58 316 59 318 60 320 61 322 62 324 63 326 64 328 65 330 66 332 67 334 68 336 69 338 70 340 71 342 72 344 73 346 74 348 75 350 76 352 77 354 78 356 79 358 80 360 81 362 82 364 83 366 84 368 85 37...