QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#160709 | #7105. Pixel Art | ucup-team1447# | AC ✓ | 185ms | 69100kb | C++14 | 5.1kb | 2023-09-02 21:10:36 | 2023-09-04 04:30:55 |
Judging History
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define ull unsigned long long
#define i128 __int128
//#define int long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define mod 1000000007
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,int b){return a.x==b;}
friend bool operator !=(modint a,int b){return a.x!=b;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 400005
#define inf 0x3f3f3f3f
int n,m,k;
int r1[maxn],r2[maxn],c1[maxn],c2[maxn];
vector<pii>a[maxn],b[maxn];
vi qs[maxn],del[maxn];
void wk(vector<pii>&o){
if(!o.size())return;
sort(o.begin(),o.end());
vector<pii>buc;
int l=-1,r=-1;
for(auto [x,y]:o){
if(l==-1) l=x,r=y;
else{
if(x<=r+1) r=max(r,y);
else {
buc.pb(mkp(l,r));
l=x,r=y;
}
}
}
if(l!=-1) buc.pb(mkp(l,r));
o=buc;
}
int t[maxn],len;
int fa[maxn],tot,don=0;
int gf(int x){
while(x^fa[x])x=fa[x]=fa[fa[x]];
return x;
}
void merge(int x,int y){
x=gf(x),y=gf(y);
if(x==y)return;
fa[x]=y,++don;
}
vi id[maxn];
ll ss[maxn];
int ids[maxn];
void work()
{
n=read(),m=read(),k=read(); don=0; len=0;
For(i,1,n) b[i].clear();
For(i,0,n+1) qs[i].clear(),del[i].clear(),ss[i]=0;
For(i,1,k){
int r1=read(),c1=read(),r2=read(),c2=read();
if(r1==r2){
b[r1].pb(mkp(c1,c2));
}else{
t[++len]=c1;
a[c1].pb(mkp(r1,r2));
ss[r1]+=1,ss[r2+1]-=1;
}
}
For(i,1,n) ss[i]+=ss[i-1];
For(i,1,n){
for(auto [l,r]:b[i]) ss[i]+=r-l+1;
}
For(i,1,n) ss[i]+=ss[i-1];
sort(t+1,t+len+1),len=unique(t+1,t+len+1)-t-1;
For(i,1,n)wk(b[i]);
For(i,1,len)wk(a[t[i]]);
For(i,1,len){
for(auto [l,r]:a[t[i]])
qs[l].pb(t[i]),del[r+1].pb(t[i]);
}
tot=0;
For(i,0,k)fa[i]=i;
ll sum=0;
For(i,1,n){
int p=0;
id[i].resize(b[i].size());
for(auto &x:id[i]) x=++tot;
int sz=b[i].size();
int p2=0;
For(j,0,sz-1){
int l=b[i][j].fi,r=b[i][j].se,u=id[i][j];
while(p2<del[i].size() && del[i][p2]<l) ++p2;
while(p2<del[i].size() && del[i][p2]<=r) {
merge(u,ids[del[i][p2]]);
++p2;
}
while(p<b[i-1].size() && b[i-1][p].se<l) ++p;
bool go=0;
while(p<b[i-1].size() && b[i-1][p].fi<=r) {
go=1;
merge(id[i-1][p],u);
++p;
}
if(go) --p;
}
for(auto it:del[i]){
ids[it]=0;
}
p=0;
for(auto x:qs[i]){
ids[x]=++tot;
}
// cout<<"tot,don "<<tot<<" "<<don<<"\n";
For(j,0,(int)qs[i].size()-1){
int x=qs[i][j],u=ids[x];
if(x>1 && ids[x-1]) merge(ids[x],ids[x-1]);
if(x<m && ids[x+1]) merge(ids[x],ids[x+1]);
}
p=0;
For(j,0,(int)b[i-1].size()-1){
int l=b[i-1][j].fi,r=b[i-1][j].se,u=id[i-1][j];
while(p<qs[i].size() && qs[i][p]<l) ++p;
while(p<qs[i].size() && qs[i][p]<=r) {
merge(u,ids[qs[i][p]]);
++p;
}
}
For(j,0,sz-1){
int l=b[i][j].fi,r=b[i][j].se,u=id[i][j];
if(l>1 && ids[l-1]) merge(u,ids[l-1]);
if(r<m && ids[r+1]) merge(u,ids[r+1]);
}
cout<<ss[i]<<" "<<tot-don<<"\n";
}
For(i,1,len){
ids[t[i]]=0;
a[t[i]].clear();
}len=0;
// For(i,1,n){
// cout<<ss[i]<<"\n";
// }
}
signed main()
{
int T=read();
while(T--)work();
return 0;
}
/*
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
*/
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 58896kb
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: 185ms
memory: 69100kb
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