QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#739942#9170. Cycle Gameucup-team134Compile Error//C++174.9kb2024-11-13 00:00:262024-11-13 00:00:29

Judging History

你现在查看的是最新测评结果

  • [2024-11-13 00:00:29]
  • 评测
  • [2024-11-13 00:00:26]
  • 提交

answer

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ld long double
#define li __int128

using namespace std;

mt19937 rng(time(NULL));

const int N=3e5+5;
struct dsu{
	vector<int> par,siz;
	vector<bool> changed;
	vector<pair<int,pair<int,int>>> old;
	int cntComp,cntCompsnap;
	bool activeSnap;
	void reset(int n){
		par.resize(n);
		siz.resize(n);
		changed.resize(n);
		iota(all(par),0);
		fill(all(changed),0);
		fill(all(siz),1);
		old.clear();
		cntComp=n;
		activeSnap=0;
	}
	void snapshot(){
		for(auto p:old){
			changed[p.f]=0;
		}
		old.clear();
		cntCompsnap=cntComp;
		activeSnap=1;
	}
	void goToSnapshot(){
		for(auto p:old){
			par[p.f]=p.s.f;
			siz[p.f]=p.s.s;
			changed[p.f]=0;
		}
		old.clear();
		cntComp=cntCompsnap;
	}
	inline int find(int tr){return tr==par[tr]?tr:find(par[tr]);}
	inline void merge(int a,int b){
		a=find(a);
		b=find(b);
		if(a==b)return;
		cntComp--;
		if(siz[a]>siz[b])swap(a,b);
		if(activeSnap&&!changed[a]){
			changed[a]=1;
			old.pb({a,{par[a],siz[a]}});
		}
		par[a]=b;
		siz[b]+=siz[a];
	}
}dsu;
vector<int> dx={1,1,1,0,-1,-1,-1,0},dy={1,0,-1,-1,-1,0,1,1};
int main()
{
	ios;
	int n,m,k;
	cin>>n>>m>>k;
	bool mx=0;
	if(n==-1){
		n=75000;
		m=4;
		k=3e5;
		mx=1;
	}
	vector<pair<int,int>> ord;
	int C=1800;
	auto inside=[&](int x,int y){
		return x>=0&&x<n&&y>=0&&y<m;
	};
	auto ind=[&](int x,int y){
		return x*m+y;
	};
	auto onBorder=[&](int x,int y){
		return x==0||y==0||x==n-1||y==m-1;
	};
	if(mx){
		for(int i=0;i<n;i++)for(int j=0;j<m;j++)ord.pb({i,j});
		shuffle(all(ord),rng);
	}
	else{
		for(int i=0;i<k;i++){
			int x,y;
			if(mx){
				x=1;
				y=rng()%m+1;
			}
			else
				cin >> x >> y;
			x--;y--;
			ord.pb({x,y});
		}
	}
	vector<vector<bool>> on(n,vector<bool>(m));
	vector<vector<bool>> next(n,vector<bool>(m));
	int cntNext=0,cntNextOld=0;
	bool inSnap=0;
	vector<pair<pair<int,int>,int>> back;
	auto reset=[&](){
		back.clear();
		cntNext=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				next[i][j]=0;
				if(on[i][j]){
					if(onBorder(i,j)){
						next[i][j]=1;
						cntNext++;
					}
					else{
						for(int kk=0;kk<8;kk++){
							int x=i+dx[kk],y=j+dy[kk];
							if(inside(x,y)&&!on[x][y]){
								next[i][j]=1;
								cntNext++;
								break;
							}
						}
					}
				}
			}
		}
		inSnap=0;
	};
	auto snap=[&](){
		back.clear();
		cntNextOld=cntNext;
		inSnap=1;
	};
	auto add=[&](int i,int j){
		if(next[i][j]){
			if(inSnap)back.pb({{i,j},1});
			next[i][j]=0;
			cntNext--;
		}
		for(int kk=0;kk<8;kk++){
			int x=i+dx[kk],y=j+dy[kk];
			if(inside(x,y)&&on[x][y]&&!next[x][y]){
				if(inSnap)back.pb({{x,y},0});
				next[x][y]=1;
				cntNext++;
			}
		}
	};
	auto bac=[&](){
		for(int i=sz(back)-1;i>=0;i--){
			next[back[i].f.f][back[i].f.s]=back[i].s;
		}
		back.clear();
		cntNext=cntNextOld;
	};
	vector<bool> ok(k,1);
	int cntDo=0;
	ll resetTime=0;
	for(int i=0;i<k;){
		int ost=min(C,k-i);
		int j=i+ost;
		//printf("%i->%i\n",i,j);
		for(int o=i;o<j;o++){
			int x=ord[o].f,y=ord[o].s;
			on[x][y]=1;
		}
		C-=5;
		ll st=clock();
		dsu.reset(n*m+1);
		reset();
		for(int x=0;x<n;x++){
			for(int y=0;y<m;y++){
				if(!on[x][y]){
					if(onBorder(x,y)){
						dsu.merge(ind(x,y),n*m);
					}
					for(int kk=0;kk<4;kk++){
						int xx=x+dx[kk],yy=y+dy[kk];
						if(inside(xx,yy)&&!on[xx][yy]){
							dsu.merge(ind(x,y),ind(xx,yy));
						}
					}
				}
			}
		}
		resetTime+=clock()-st;
		cntDo++;
		//printf("CntComp: %i\n",dsu.cntComp);
		while(1){
			if(dsu.cntComp-cntNext==1){ // everything is ok
				break;
			}
			dsu.snapshot();
			snap();
			for(int o=j-1;o>=i-1;o--){
				assert(o!=i-1);
				int x=ord[o].f,y=ord[o].s;
				assert(on[x][y]);
				on[x][y]=0;
				add(x,y);
				if(onBorder(x,y)){
					dsu.merge(ind(x,y),n*m);
				}
				for(int kk=0;kk<8;kk++){
					int xx=x+dx[kk],yy=y+dy[kk];
					if(inside(xx,yy)&&!on[xx][yy]){
						dsu.merge(ind(x,y),ind(xx,yy));
					}
				}
				if(dsu.cntComp-cntNext==1){
					ok[o]=0;
					dsu.goToSnapshot();
					bac();
					for(int p=o+1;p<j;p++){
						on[ord[p].f][ord[p].s]=1;
					}
					add(x,y);
					if(onBorder(x,y)){
						dsu.merge(ind(x,y),n*m);
					}
					for(int kk=0;kk<8;kk++){
						int xx=x+dx[kk],yy=y+dy[kk];
						if(inside(xx,yy)&&!on[xx][yy]){
							dsu.merge(ind(x,y),ind(xx,yy));
						}
					}
					break;
				}
			}
		}
		i=j;
	}
	if(mx)
	printf("%i\n",cntDo),printf("%lld\n",resetTime),printf("C: %i\n",C);
	for(int i=0;i<k;i++){
		printf(ok[i]?"1":"0");
	}
	printf("\n");
	return 0;
}

Details

In file included from /usr/include/c++/13/string:43,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from answer.code:3:
/usr/include/c++/13/bits/allocator.h: In destructor ‘std::_Bvector_base<std::allocator<bool> >::_Bvector_impl::~_Bvector_impl()’:
/usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to ‘always_inline’ ‘std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = long unsigned int]’: target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/13/vector:67,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53:
/usr/include/c++/13/bits/stl_bvector.h:557:14: note: called from here
  557 |       struct _Bvector_impl
      |              ^~~~~~~~~~~~~