QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#159172 | #7105. Pixel Art | ucup-team1004# | WA | 483ms | 19412kb | C++14 | 3.2kb | 2023-09-02 17:35:01 | 2023-09-02 17:35:04 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=1e5+5,M=N*25+5,K=600+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(time(0));
int n,m,k;
struct Node{int x,y,id;};
vector<Node> S1[N],S2[N];
int fa[N];ll f1[N],f2[N];
int GF(int x){return fa[x]^x?fa[x]=GF(fa[x]):x;}
set<pii > f;
void Solve(){
int i,j;scanf("%d%d%d",&n,&m,&k);
for(i=1;i<=n;i++) S1[i].clear(),S2[i].clear(),f1[i]=f2[i]=0;
for(i=1;i<=k;i++) {
int r1,c1,r2,c2;
scanf("%d%d%d%d",&r1,&c1,&r2,&c2);
if(r1==r2) S1[r1].push_back((Node){c1,c2,i}),f2[r1]+=c2-c1+1;
else S2[r1].push_back((Node){c1,1,i}),S2[r2+1].push_back((Node){c1,-1,i}),f1[r1]++,f1[r2+1]--;
}
f.clear();int Ct=0;
auto Mg=[&Ct](int x,int y){
x=GF(x);y=GF(y);if(x^y) fa[x]=y,Ct--;//cerr<<x<<' '<<y<<'\n';
};
for(i=1;i<=n;i++) f1[i]+=f1[i-1];
for(i=1;i<=n;i++) {
f1[i]+=f1[i-1];f2[i]+=f2[i-1];printf("%lld ",f1[i]+f2[i]);
for(auto j:S2[i]) if(j.y==1) fa[j.id]=j.id,Ct++;
for(auto j:S1[i]) fa[j.id]=j.id,Ct++;
set<tuple<int,int,int> > g;
for(auto j:S1[i-1]) g.emplace(j.x,j.y,j.id);
for(auto j:S2[i]) if(j.y==1){
auto p=g.LB({j.x+1,0,0});
if(p==g.begin()) continue;
p--;if(get<0>(*p)<=j.x&&get<1>(*p)>=j.x) Mg(get<2>(*p),j.id);
}
sort(S1[i].begin(),S1[i].end(),[](Node x,Node y){return x.x<y.x;});
for(int j=1;j<S1[i].size();j++) if(S1[i][j-1].y==S1[i][j].x-1) Mg(S1[i][j-1].id,S1[i][j].id);
for(auto j:S1[i]){
auto p=g.LB({j.x+1,0,0});
if(p!=g.begin()) p--;
while(p!=g.end()){
auto q=*p;p++;
if(get<1>(q)<j.x) continue;
if(get<0>(q)>j.y) break;
Mg(get<2>(q),j.id);
}
}
g.clear();
for(auto j:S1[i]) g.emplace(j.x,j.y,j.id);
for(auto j:S2[i]) if(j.y==-1){
auto p=g.UB({j.x+1,0,0});
if(p==g.begin()) continue;
p--;if(get<0>(*p)<=j.x&&get<1>(*p)>=j.x) Mg(get<2>(*p),j.id);
}else{
auto p=g.LB({j.x,0,0});
if(p!=g.begin()&&get<1>(*--p)==j.x-1) Mg(get<2>(*p),j.id);
p=g.LB({j.y+1,0,0});
if(p!=g.end()&&get<0>(*p)==j.y+1) Mg(get<2>(*p),j.id);
}
for(auto j:S2[i]) if(j.y==1){
auto p=f.LB(make_pair(j.x,0));
if(p!=f.end()&&p->fi==j.x) Mg(p->se,j.id);
}
for(auto j:S2[i]) if(j.y==-1) f.erase(make_pair(j.x,j.id));
for(auto j:S2[i]) if(j.y==1){
auto p=f.LB(make_pair(j.x-1,0));
if(p!=f.end()&&p->fi==j.x-1) Mg(p->se,j.id);
p=f.LB(make_pair(j.x+1,0));
if(p!=f.end()&&p->fi==j.x+1) Mg(p->se,j.id);
f.emplace(j.x,j.id);
}
for(auto j:S1[i]){
auto p=f.LB(make_pair(j.x-1,0));
if(p!=f.end()&&p->fi==j.x-1) Mg(p->se,j.id);
p=f.LB(make_pair(j.y+1,0));
if(p!=f.end()&&p->fi==j.y+1) Mg(p->se,j.id);
f.emplace(j.x,j.id);
}
printf("%d\n",Ct);
}
}
int main(){
int t;
scanf("%d",&t);
// t=1;
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 8864kb
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: 483ms
memory: 19412kb
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:
wrong answer 115th lines differ - expected: '10 10', found: '10 1'