QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#160111#7105. Pixel Artucup-team191#AC ✓818ms138624kbC++238.2kb2023-09-02 19:29:172023-09-02 19:29:18

Judging History

你现在查看的是测评时间为 2023-09-02 19:29:18 的历史记录

  • [2023-09-04 04:30:51]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:859ms
  • 内存:142492kb
  • [2023-09-02 19:29:18]
  • 评测
  • 测评结果:100
  • 用时:818ms
  • 内存:138624kb
  • [2023-09-02 19:29:17]
  • 提交

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=1000010;
int t,n,m,k,r1[N],c1[N],r2[N],c2[N],par[N],rid[N];
ll cb[N];
vi ch[N];
vector<pii> hor[N],ver[N];

bool inHor(int x,int y)
{
	if (x<1 || x>n || y<1 || y>m) return 0;
	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)
{
	if (x<1 || x>n || y<1 || y>m) return 0;
	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);
	//freopen("oof.txt","r",stdin);
	for (int i=0;i<N;++i) ch[i].reserve(4);
	cin>>t;
	while (t--)
	{
		cin>>n>>m>>k;
		vi 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.pb(r1[i]);
			}
			else
			{
				ver[c1[i]].pb({r1[i],r2[i]});
				++cb[r1[i]];
				--cb[r2[i]+1];
				cve.pb(c1[i]);
			}
		}
		sort(all(rho));
		rho.erase(unique(all(rho)),rho.end());
		sort(all(cve));
		cve.erase(unique(all(cve)),cve.end());
		for (int i=2;i<=n;++i) cb[i]+=cb[i-1];
		for (int i=0;i<k;++i) if (r1[i]==r2[i]) cb[r1[i]]+=c2[i]-c1[i]+1;
		for (int i=2;i<=n;++i) cb[i]+=cb[i-1];
		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({r1[i],c1[i]-1});
				cand.pb({r2[i],c2[i]});
				cand.pb({r2[i]-1,c2[i]});
				cand.pb({r2[i]+1,c2[i]});
				cand.pb({r2[i],c2[i]+1});
			}
			else
			{
				cand.pb({r1[i],c1[i]});
				cand.pb({r1[i]-1,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]+1,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;
			}*/
		}
		//continue;
		for (int i=0;i<k;++i) if (r1[i]==r2[i])
		{
			int p=lower_bound(all(no),pii(r1[i],c1[i]))-no.begin();
			while (p<(int)no.size()-1 && no[p+1].x==r1[i] && no[p+1].y<=c2[i])
			{
				ch[p].pb(p+1);
				ch[p+1].pb(p);
				++p;
			}
		}
		vector<pii> trno(no.size());
		for (int i=0;i<(int)no.size();++i) trno[i]={no[i].y,no[i].x};
		sort(all(trno));
		for (int i=0;i<(int)no.size();++i) rid[i]=lower_bound(all(no),pii(trno[i].y,trno[i].x))-no.begin();
		
		for (int i=0;i<(int)no.size()-1;++i)
		{
			int a=rid[i];
			int b=rid[i+1];
			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<k;++i) if (r1[i]!=r2[i])
		{
			int p=lower_bound(all(trno),pii(c1[i],r1[i]))-trno.begin();
			while (p<(int)trno.size()-1 && trno[p+1].x==c1[i] && trno[p+1].y<=r2[i])
			{
				ch[rid[p]].pb(rid[p+1]);
				ch[rid[p+1]].pb(rid[p]);
				++p;
			}
		}
		/*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<<cb[j]<<' '<<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();
		for (int i=1;i<=n+1;++i) cb[i]=0;
	}
}





这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 30ms
memory: 118208kb

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: 818ms
memory: 138624kb

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