QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#161352 | #7105. Pixel Art | ucup-team134# | WA | 330ms | 12448kb | C++14 | 2.8kb | 2023-09-02 23:29:27 | 2023-09-02 23:29:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
const int N=100050;
int ans;
int p[N];
int Find(int x){return p[x]==x?x:p[x]=Find(p[x]);}
void Union(int x,int y){
//printf("Union %i %i\n",x,y);
x=Find(x);
y=Find(y);
if(x!=y){
ans--;
p[x]=y;
}
}
void Init(int n){for(int i=1;i<=n;i++)p[i]=i;}
vector<array<int,3>> hor[N];
int active[N];
int ss[N],se[N],add[N];
int main(){
int t;
scanf("%i",&t);
while(t--){
int n,m,k;
scanf("%i %i %i",&n,&m,&k);
Init(k);
vector<int> xs;
vector<array<int,3>> evs;
for(int i=1;i<=k;i++){
int x1,y1,x2,y2;
scanf("%i %i %i %i",&x1,&y1,&x2,&y2);
if(x1==x2){
hor[x1].pb({y1,y2,i});
xs.pb(x1);
add[x1]+=y2-y1+1;
}else{
//ver[y1].pb({x1,x2,i});
//ys.pb(y1);
evs.pb({x1,y1,-i});
evs.pb({x2+1,y1,i});
ss[x1]++;
se[x2]++;
}
}
sort(xs.begin(),xs.end());
xs.erase(unique(xs.begin(),xs.end()),xs.end());
//sort(ys.begin(),ys.end());
//ys.erase(unique(ys.begin(),ys.end()),ys.end());
for(int x:xs)sort(hor[x].begin(),hor[x].end());
//for(int y:ys)sort(ver[y].begin(),ver[y].end());
ll blk=0,tmp=0;
sort(evs.begin(),evs.end());
int ptr=0;
set<int> act;
ans=0;
for(int i=1;i<=n+1;i++){
blk+=add[i];
tmp+=ss[i];
blk+=tmp;
tmp-=se[i];
int j=0;
array<int,3> last={-1,-1,-1};
for(auto h:hor[i]){
ans++;
while(j<hor[i-1].size() && hor[i-1][j][1]<h[0])j++;
while(j<hor[i-1].size() && hor[i-1][j][0]<=h[1]){
Union(h[2],hor[i-1][j][2]);
j++;
}
if(j>0){
j--;
}
for(auto it=act.lower_bound(h[0]);it!=act.upper_bound(h[1]);it++){
Union(h[2],active[*it]);
}
if(last[1]+1==h[0]){
Union(last[2],h[2]);
}
last=h;
}
j=0;
while(ptr<evs.size() && evs[ptr][0]==i){
int x=evs[ptr][0];
int y=evs[ptr][1];
int idx=abs(evs[ptr][2]);
if(evs[ptr][2]<0){
if(active[y]){
Union(active[y],idx);
}
while(j<hor[i-1].size() && hor[i-1][j][1]<y)j++;
if(j<hor[i-1].size() && hor[i-1][j][0]<=y){
Union(idx,hor[i-1][j][2]);
}
active[y]=idx;
act.insert(y);
ans++;
}else{
if(active[y]==idx){
active[y]=0;
act.erase(y);
}
}
ptr++;
}
for(auto h:hor[i]){
if(active[h[0]-1]!=0){
Union(active[h[0]-1],h[2]);
}
if(active[h[1]+1]!=0){
Union(active[h[1]+1],h[2]);
}
}
if(i<=n){
printf("%lld %i\n",blk,ans);
}
}
for(int x:xs){
hor[x].clear();
}
/*for(int y:ys){
ver[y].clear();
}*/
for(int i=0;i<=n+1;i++){
add[i]=ss[i]=se[i]=0;
//bal[i]=0;
//spec[i]=0;
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 7520kb
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
Wrong Answer
time: 330ms
memory: 12448kb
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 100 200 100 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 ...
result:
wrong answer 12th lines differ - expected: '150 1', found: '150 100'