QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#161167 | #7105. Pixel Art | ucup-team266# | AC ✓ | 641ms | 35400kb | C++14 | 5.6kb | 2023-09-02 22:47:06 | 2023-09-04 04:31:00 |
Judging History
answer
/*
Things to notice:
1. do not calculate useless values
2. do not use similar names
Things to check:
1. submit the correct file
2. time (it is log^2 or log)
3. memory
4. prove your naive thoughts
5. long long
6. corner case like n=0,1,inf or n=m
7. check if there is a mistake in the ds or other tools you use
8. fileio in some oi-contest
9. module on time
10. the number of a same divisor in a math problem
11. multi-information and queries for dp and ds problems
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pii pair<long long,long long>
#define mp make_pair
#define pb push_back
const int mod=998244353;
const int inf=0x3f3f3f3f;
const int INF=1e18;
int n,m,k;
int fa[100005];
int find(int x)
{
if(fa[x]==x) return x;
return fa[x]=find(fa[x]);
}
int merge(int x,int y)
{
int xx=find(x),yy=find(y);
if(xx!=yy)
{
fa[xx]=yy;
return 1;
}
return 0;
}
vector <int> add[100005],del[100005];
vector <int> has[100005];
vector <array<int,3> > has2[100005];
int flg[100005];
pii ans[100005];
int R1[100005],R2[100005],C1[100005],C2[100005];
void solve()
{
cin>>n>>m>>k;
for(int i=1;i<=n+1;i++) add[i].clear(),del[i].clear(),has[i].clear(),ans[i]=mp(0,0);
for(int i=1;i<=k;i++)
{
fa[i]=i;
cin>>R1[i]>>C1[i]>>R2[i]>>C2[i];
if(R1[i]==R2[i]) has[R1[i]].pb(i);
else add[R1[i]].pb(i),del[R2[i]+1].pb(i);
}
int now=0,sum=0;
for(int i=1;i<=n;i++)
{
now+=add[i].size(),now-=del[i].size(),sum+=now;
for(int j=0;j<has[i].size();j++) sum+=C2[has[i][j]]-C1[has[i][j]]+1;
ans[i].fi=sum;
}
set <pii > S;
S.clear();
vector <array<int,4> > vec;
vector <array<int,4> > inter;
// same row/col
for(int i=1;i<=k;i++) if(R1[i]==R2[i]) vec.pb({R1[i],C1[i],C2[i],i});
sort(vec.begin(),vec.end());
for(int i=0;i+1<vec.size();i++) if(vec[i][0]==vec[i+1][0]&&vec[i][2]+1==vec[i+1][1]) inter.pb({vec[i][0],vec[i][2],vec[i][3],vec[i+1][3]});
vec.clear();
for(int i=1;i<=k;i++) if(R1[i]!=R2[i]) vec.pb({C1[i],R1[i],R2[i],i});
sort(vec.begin(),vec.end());
for(int i=0;i+1<vec.size();i++) if(vec[i][0]==vec[i+1][0]&&vec[i][2]+1==vec[i+1][1]) inter.pb({vec[i+1][1],vec[i][0],vec[i][3],vec[i+1][3]});
// 1 hor and 1 ver
for(int i=1;i<=n;i++)
{
for(int j=0;j<del[i].size();j++) S.erase(mp(C1[del[i][j]],del[i][j]));
for(int j=0;j<add[i].size();j++) S.insert(mp(C1[add[i][j]],add[i][j]));
for(int j=0;j<has[i].size();j++)
{
int u=has[i][j];
int L=C1[u],R=C2[u];
auto it=S.lower_bound(mp(L-1,-1LL));
if(it!=S.end()&&(*it).fi==L-1) inter.pb({i,L-1,u,(*it).se});
it=S.lower_bound(mp(R+1,-1LL));
if(it!=S.end()&&(*it).fi==R+1) inter.pb({i,R,u,(*it).se});
}
}
S.clear();
for(int i=1;i<=n;i++)
{
for(int j=0;j<add[i].size();j++) S.insert(mp(C1[add[i][j]],add[i][j]));
for(int j=0;j<has[i].size();j++)
{
int u=has[i][j];
int L=C1[u],R=C2[u];
auto it=S.lower_bound(mp(L,-1LL));
while(it!=S.end())
{
int x=(*it).fi,v=(*it).se;
if(L<=x&&x<=R) inter.pb({i,x,u,v});
if(x>R) break;
it++;
}
}
for(int j=0;j<del[i].size();j++) S.erase(mp(C1[del[i][j]],del[i][j]));
}
S.clear();
for(int i=n;i>=1;i--)
{
for(int j=0;j<del[i+1].size();j++) S.insert(mp(C1[del[i+1][j]],del[i+1][j]));
for(int j=0;j<has[i].size();j++)
{
int u=has[i][j];
int L=C1[u],R=C2[u];
auto it=S.lower_bound(mp(L,-1LL));
while(it!=S.end())
{
int x=(*it).fi,v=(*it).se;
if(L<=x&&x<=R) inter.pb({i+1,x,u,v});
if(x>R) break;
it++;
}
}
for(int j=0;j<add[i+1].size();j++) S.erase(mp(C1[add[i+1][j]],add[i+1][j]));
}
// row diff =1
for(int i=1;i<=k;i++) if(R1[i]==R2[i])
{
flg[R1[i]]=1;
has2[R1[i]].pb({C1[i],C2[i],i});
}
for(int i=1;i<=k;i++) if(R1[i]==R2[i]&&flg[R1[i]]) sort(has2[R1[i]].begin(),has2[R1[i]].end()),flg[R1[i]]=0;
for(int i=1;i<=k;i++) if(R1[i]==R2[i])
{
int L=C1[i],R=C2[i];
array<int,3> T={L,-1LL,-1LL};
int p=lower_bound(has2[R1[i]+1].begin(),has2[R1[i]+1].end(),T)-has2[R1[i]+1].begin()-1;
p=max(p,0LL);
// cout<<"... "<<i<<" "<<p<<" "<<R1[i]+1<<" "<<has2[R1[i]+1].size()<<"\n";
while(p<has2[R1[i]+1].size())
{
int LL=has2[R1[i]+1][p][0],RR=has2[R1[i]+1][p][1],v=has2[R1[i]+1][p][2];
if(LL>R) break;
if(min(RR,R)-max(LL,L)+1>=1) inter.pb({R1[i]+1,-1,i,v});
p++;
}
}
for(int i=1;i<=k;i++) if(R1[i]==R2[i]) has2[R1[i]].clear();
// cout<<"...\n";
// col diff=1
for(int i=1;i<=k;i++) if(R1[i]!=R2[i])
{
flg[C1[i]]=1;
has2[C1[i]].pb({R1[i],R2[i],i});
}
for(int i=1;i<=k;i++) if(R1[i]!=R2[i]&&flg[C1[i]]) sort(has2[C1[i]].begin(),has2[C1[i]].end()),flg[C1[i]]=0;
for(int i=1;i<=k;i++) if(R1[i]!=R2[i])
{
int L=R1[i],R=R2[i];
array<int,3> T={L,-1LL,-1LL};
int p=lower_bound(has2[C1[i]+1].begin(),has2[C1[i]+1].end(),T)-has2[C1[i]+1].begin()-1;
p=max(p,0LL);
while(p<has2[C1[i]+1].size())
{
int LL=has2[C1[i]+1][p][0],RR=has2[C1[i]+1][p][1],v=has2[C1[i]+1][p][2];
if(LL>R) break;
if(min(RR,R)-max(LL,L)+1>=1) inter.pb({max(L,LL),-1,i,v});
p++;
}
}
for(int i=1;i<=k;i++) if(R1[i]!=R2[i]) has2[C1[i]].clear();
// cout<<"...\n";
sort(inter.begin(),inter.end());
sum=0;
for(int i=1,j=0;i<=n;i++)
{
sum+=add[i].size()+has[i].size();
while(j<inter.size()&&inter[j][0]==i) sum-=merge(inter[j][2],inter[j][3]),j++;
ans[i].se=sum;
}
for(int i=1;i<=n;i++) cout<<ans[i].fi<<" "<<ans[i].se<<"\n";
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int _=1;
cin>>_;
while(_--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 18544kb
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: 641ms
memory: 35400kb
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