QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#159807 | #7105. Pixel Art | ucup-team191# | WA | 771ms | 51664kb | C++23 | 7.0kb | 2023-09-02 18:45:38 | 2023-09-02 18:45:39 |
Judging History
answer
//DUEL
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")
#define shandom_ruffle(a, b) shuffle(a, b, rng)
#define vi vector<int>
#define vl vector<ll>
#define popcnt __builtin_popcountll
#define all(a) begin(a),end(a)
//for kactl
#define sz(x) (int)(x).size()
#define rep(i, a, b) for(int i = a; i < (b); ++i)
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w,bool fl=false)
{
cout<<w.size()<<en;
for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
if (w.size()) cout<<w[w.size()-1]<<en;
if (fl) cout<<flush;
}
void M998()
{
swap(MOD,MOD2);
}
ll raand()
{
ll a=rund();
a*=RAND_MAX;
a+=rund();
return a;
}
#define rand raand
ll raaand()
{
return raand()*(MOD-7)+raand();
}
template<class T>
vi compress(vector<T>&v)
{
set<T> s;
for (auto a: v) s.insert(a);
vector<T> o(all(s));
vi nv;
for (int i=0;i<(int)v.size();++i) nv.pb(lower_bound(all(o),v[i])-o.begin());
return nv;
}
string to_upper(string a)
{
for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
return a;
}
string to_lower(string a)
{
for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
return a;
}
ll sti(string a,int base=10)
{
ll k=0;
for (int i=0;i<(int)a.size();++i)
{
k*=base;
k+=a[i]-'0';
}
return k;
}
template<class T>
void eras(vector<T>& a,T b)
{
a.erase(find(a.begin(),a.end(),b));
}
string its(ll k,int base=10)
{
if (k==0) return "0";
string a;
while (k)
{
a.push_back((k%base)+'0');
k/=base;
}
reverse(a.begin(),a.end());
return a;
}
ll min(ll a,int b)
{
if (a<b) return a;
return b;
}
ll min(int a,ll b)
{
if (a<b) return a;
return b;
}
ll max(ll a,int b)
{
if (a>b) return a;
return b;
}
ll max(int a,ll b)
{
if (a>b) return a;
return b;
}
ll gcd(ll a,ll b)
{
if (b==0) return a;
return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
return a/gcd(a,b)*b;
}
template<class T,class K>
pair<T,K> mp(T a,K b)
{
return make_pair(a,b);
}
inline int mult(ll a,ll b)
{
return (a*b)%MOD;
}
inline int pot(int n,int k)
{
if (k==0) return 1;
ll a=pot(n,k/2);
a=mult(a,a);
if (k%2) return mult(a,n);
else return a;
}
int divide(int a,int b)
{
return mult(a,pot(b,MOD-2));
}
inline int sub(int a,int b)
{
if (a-b>=0) return a-b;
return a-b+MOD;
}
inline int add(int a,int b)
{
if (a+b>=MOD) return a+b-MOD;
return a+b;
}
void ad(int&a,int b)
{
a+=b;
if (a>=MOD) a-=MOD;
}
void su(int&a,int b)
{
a-=b;
if (a<0) a+=MOD;
}
bool prime(ll a)
{
if (a==1) return 0;
for (int i=2;i<=round(sqrt(a));++i)
{
if (a%i==0) return 0;
}
return 1;
}
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
const int N=300010;
int t,n,m,k,r1[N],c1[N],r2[N],c2[N],par[N];
vi ch[N];
vector<pii> hor[N],ver[N];
bool inHor(int x,int y)
{
auto it=lower_bound(all(hor[x]),pii(y+1,0));
if (it==hor[x].begin()) return 0;
--it;
return (it->y)>=y;
}
bool inVer(int x,int y)
{
auto it=lower_bound(all(ver[y]),pii(x+1,0));
if (it==ver[y].begin()) return 0;
--it;
return (it->y)>=x;
}
int find(int i)
{
if (i==par[i]) return i;
return par[i]=find(par[i]);
}
bool mer(int a,int b)
{
a=find(a);
b=find(b);
if (a==b) return 0;
par[a]=b;
return 1;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829*2)+13893829);
cin>>t;
while (t--)
{
cin>>n>>m>>k;
set<int> rho,cve;
for (int i=0;i<k;++i)
{
cin>>r1[i]>>c1[i]>>r2[i]>>c2[i];
if (r1[i]==r2[i])
{
hor[r1[i]].pb({c1[i],c2[i]});
rho.insert(r1[i]);
}
else
{
ver[c1[i]].pb({r1[i],r2[i]});
cve.insert(c1[i]);
}
}
for (auto x: rho) sort(all(hor[x]));
for (auto x: cve) sort(all(ver[x]));
vector<pii> cand,no;
for (int i=0;i<k;++i)
{
if (r1[i]==r2[i])
{
cand.pb({r1[i],c1[i]});
cand.pb({r1[i]-1,c1[i]});
cand.pb({r1[i]+1,c1[i]});
cand.pb({r2[i],c2[i]});
cand.pb({r2[i]-1,c2[i]});
cand.pb({r2[i]+1,c2[i]});
}
else
{
cand.pb({r1[i],c1[i]});
cand.pb({r1[i],c1[i]+1});
cand.pb({r1[i],c1[i]-1});
cand.pb({r2[i],c2[i]});
cand.pb({r2[i],c2[i]-1});
cand.pb({r2[i],c2[i]+1});
}
}
sort(all(cand));
cand.erase(unique(all(cand)),cand.end());
for (auto x: cand) if (inHor(x.x,x.y) || inVer(x.x,x.y)) no.pb(x);
for (int i=0;i<(int)no.size()-1;++i)
{
if (no[i].x!=no[i+1].x) continue;
if (no[i].y+1==no[i+1].y)
{
ch[i].pb(i+1);
ch[i+1].pb(i);
continue;
}
auto it=lower_bound(all(hor[no[i].x]),pii(no[i].y+1,0));
if (it==hor[no[i].x].begin()) continue;
--it;
int po=it->x,kr=it->y;
if (no[i].y>=po && no[i].y<=kr && no[i+1].y>=po && no[i+1].y<=kr)
{
ch[i].pb(i+1);
ch[i+1].pb(i);
continue;
}
}
vector<pii> trno;
for (auto x: no) trno.pb({x.y,x.x});
sort(all(trno));
for (int i=0;i<(int)no.size()-1;++i)
{
int a=lower_bound(all(no),pii(trno[i].y,trno[i].x))-no.begin();
int b=lower_bound(all(no),pii(trno[i+1].y,trno[i+1].x))-no.begin();
if (trno[i].x!=trno[i+1].x) continue;
if (trno[i].y+1==trno[i+1].y)
{
ch[a].pb(b);
ch[b].pb(a);
continue;
}
auto it=lower_bound(all(ver[trno[i].x]),pii(trno[i].y+1,0));
if (it==ver[trno[i].x].begin()) continue;
--it;
int po=it->x,kr=it->y;
if (trno[i].y>=po && trno[i].y<=kr && trno[i+1].y>=po && trno[i+1].y<=kr)
{
ch[a].pb(b);
ch[b].pb(a);
continue;
}
}
/*for (int i=0;i<(int)no.size();++i)
{
cout<<no[i].x<<' '<<no[i].y<<en<<ch[i].size()<<en;
for (auto x: ch[i]) cout<<no[x].x<<' '<<no[x].y<<en;
cout<<en;
}
cout<<en<<en;*/
for (int i=0;i<(int)no.size();++i) par[i]=i;
int cn=0,cc=0;
for (int i=0;i<no[0].x-1;++i) cout<<"0 0\n";
for (int i=0;i<(int)no.size();++i)
{
++cn;
if (i && no[i].x==no[i-1].x)
{
bool spo=0;
for (auto x: ch[i]) if (x==i-1) spo=1;
if (spo) cn+=no[i].y-no[i-1].y-1;
}
++cc;
for (auto x: ch[i]) if (x<i && mer(x,i)) --cc;
int dok=n+1;
if (i<(int)no.size()-1) dok=no[i+1].x;
for (int j=no[i].x;j<dok;++j) cout<<cn<<' '<<cc<<en;
}
for (auto x: rho) hor[x].clear();
for (auto x: cve) ver[x].clear();
for (int i=0;i<(int)no.size();++i) ch[i].clear();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 29280kb
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: 771ms
memory: 51664kb
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 50 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 ...
result:
wrong answer 10th lines differ - expected: '200 1', found: '200 50'