QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#543618#9170. Cycle GameexpectantWA 17ms112576kbC++143.4kb2024-09-01 17:32:352024-09-01 17:32:35

Judging History

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

  • [2024-09-01 17:32:35]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:112576kb
  • [2024-09-01 17:32:35]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=(k);++i)
#define drp(i,j,k) for(int i=j;i>=(k);--i)
#define mp std::make_pair
#define MAXN 1000005
typedef long long ll;
typedef std::pair<int,int> pii;
const int dx[8]={1,-1,0,0,1,1,-1,-1};
const int dy[8]={0,0,1,-1,1,-1,1,-1};
int n,m,k,cnt,a[MAXN],anc[MAXN],size[MAXN];
std::string ans;
pii seq[MAXN];
std::vector<int> tim[MAXN];
inline int code(int x,int y){
	if(x<1||y<1||x>n||y>m) return n*m+1;
	return (x-1)*m+y;
}
inline int find(int x){
	if(anc[x]==x) return x;
	return find(anc[x]);
}
namespace sgt{
	struct node{
		node *ls,*rs;
		std::vector<pii> vec;
	}pool[MAXN<<1],*pos=pool,*root;
	#define mid (l+r>>1)
	#define lson tree->ls,l,mid
	#define rson tree->rs,mid+1,r
	inline void build(node *&tree,int l,int r){
		tree=++pos;
		if(l!=r) build(lson),build(rson);
	}
	inline void ins(node *tree,int l,int r,int x,int y,pii e){
//		if(e==mp(8,11)&&x<=l&&r<=y) std::cerr<<"ins "<<l<<' '<<r<<'\n';
		if(x<=l&&r<=y) return tree->vec.push_back(e),void();
		if(x<=mid) ins(lson,x,y,e);
		if(y>mid) ins(rson,x,y,e);
	}
	inline void solve(node *tree,int l,int r){
		std::vector<pii> tmp;
//		std::cerr<<"solve "<<l<<' '<<r<<'\n';
		for(auto x:tree->vec){
			int fx=find(x.first),fy=find(x.second);
//			std::cerr<<"qwq "<<x.first<<' '<<x.second<<' '<<fx<<' '<<fy<<'\n';
			if(fx==fy) continue;
//			std::cerr<<"qwq "<<x.first<<' '<<x.second<<'\n';
			if(size[fx]>size[fy]) std::swap(fx,fy);
			anc[fx]=fy,size[fy]+=size[fx];
			tmp.emplace_back(fx,fy);
		}
//		rep(i,1,n) rep(j,1,m) std::cerr<<find(code(i,j))<<" \n"[j==m];
//		std::cerr<<find(n*m+1)<<'\n';
		if(l==r){
		    rep(i,1,n) rep(j,1,m) std::cerr<<a[code(i,j)]<<" \n"[j==m];
		    std::cerr<<'\n';
//			std::cerr<<cnt<<' '<<size[find(n*m+1)]<<'\n';
		    int u=code(seq[l].first,seq[l].second);
			if(size[find(n*m+1)]==n*m-cnt) ++cnt,a[u]=1,ans+='1';
			else{
				ans+='0';
			    rep(i,0,7){
				    int nx=seq[l].first+dx[i],ny=seq[l].second+dy[i];
				    int v=code(nx,ny);
				    if(a[v]) continue;
				    else{
					    int t1=*std::upper_bound(tim[u].begin(),tim[u].end(),l);
					    int t2=*std::upper_bound(tim[v].begin(),tim[v].end(),l);
					    if(l+1<=std::min(t1,t2)-1) ins(root,1,k,l+1,std::min(t1,t2)-1,mp(u,v));
				    }
			    }
		    }
		    std::cerr<<"QWQ "<<ans.back()<<'\n';
		}
		else solve(lson),solve(rson);
		std::reverse(tmp.begin(),tmp.end());
		for(auto x:tmp) anc[x.first]=x.first,size[x.second]-=size[x.first];
	}
}
using namespace sgt;
int main(){
	std::ios::sync_with_stdio(0);
	std::cin.tie(0),std::cout.tie(0);
	std::cin>>n>>m>>k;
	rep(i,1,k){
		std::cin>>seq[i].first>>seq[i].second;
		tim[code(seq[i].first,seq[i].second)].push_back(i);
	}
	build(root,1,k);
	rep(i,1,n*m+1) anc[i]=i,size[i]=1,tim[i].push_back(k+1);
//	rep(i,1,n) rep(j,1,m) std::cerr<<i<<' '<<j<<' '<<code(i,j)<<'\n';
	rep(i,1,n) rep(j,1,m){
		int u=code(i,j);
		std::vector<int> tmp;
		if(i==1||j==1||i==n||j==m) tmp.push_back(n*m+1);
		if(i!=n) tmp.push_back(code(i+1,j));
		if(j!=m) tmp.push_back(code(i,j+1));
		if(i!=n&&j!=1) tmp.push_back(code(i+1,j-1));
		if(i!=n&&j!=m) tmp.push_back(code(i+1,j+1));
		for(auto v:tmp){
			int t1=tim[u][0],t2=tim[v][0];
//			std::cerr<<u<<' '<<v<<' '<<std::min(t1,t2)<<'\n';
			if(std::min(t1,t2)>1) ins(root,1,k,1,std::min(t1,t2)-1,mp(u,v));
		}
    }
//	std::cerr<<"QAQ\n";
	solve(root,1,k);
	std::cout<<ans<<'\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 11ms
memory: 109824kb

input:

4 3 7
2 1
2 2
2 3
3 1
3 2
4 1
4 2

output:

1111111

result:

ok "1111111"

Test #2:

score: 0
Accepted
time: 14ms
memory: 109856kb

input:

3 3 8
1 1
1 2
1 3
2 3
3 3
3 2
3 1
2 1

output:

11111110

result:

ok "11111110"

Test #3:

score: 0
Accepted
time: 7ms
memory: 109708kb

input:

10 10 7
9 1
6 6
3 8
8 7
5 10
1 7
1 2

output:

1111111

result:

ok "1111111"

Test #4:

score: 0
Accepted
time: 15ms
memory: 110864kb

input:

9 10 50
1 9
1 6
2 3
3 1
7 4
9 4
1 3
2 5
9 2
7 9
5 6
8 10
9 5
5 5
4 10
9 7
5 9
3 2
4 5
1 1
4 7
3 6
2 8
4 3
8 6
5 10
4 8
5 4
7 2
9 6
4 2
7 8
5 2
3 5
9 1
6 1
1 5
9 9
5 8
6 3
8 8
8 4
7 7
7 1
3 7
2 2
3 10
6 9
8 3
7 6

output:

11111111111111111111111111111111111111111111111111

result:

ok "11111111111111111111111111111111111111111111111111"

Test #5:

score: 0
Accepted
time: 17ms
memory: 110460kb

input:

3 5 11
1 5
2 4
1 2
1 3
3 3
3 1
3 4
2 3
1 4
2 1
2 5

output:

11111111111

result:

ok "11111111111"

Test #6:

score: 0
Accepted
time: 11ms
memory: 112576kb

input:

7 9 12
7 3
2 3
6 2
2 2
4 2
2 8
5 7
4 4
6 8
2 7
7 2
1 9

output:

111111111111

result:

ok "111111111111"

Test #7:

score: 0
Accepted
time: 8ms
memory: 110584kb

input:

1 4 1
1 2

output:

1

result:

ok "1"

Test #8:

score: -100
Wrong Answer
time: 15ms
memory: 111092kb

input:

9 8 67
5 5
8 3
9 5
7 4
5 1
9 3
4 2
2 5
1 7
7 8
7 2
8 5
6 1
8 8
4 4
5 4
1 5
3 4
6 7
2 3
3 7
5 7
2 4
2 7
1 3
7 3
2 8
6 6
6 2
6 3
7 5
9 6
7 6
3 6
1 1
6 4
3 1
5 3
8 7
2 1
4 1
8 4
8 6
3 5
5 8
1 6
1 2
4 6
9 4
1 4
3 3
4 8
8 1
4 7
9 8
3 8
6 5
6 8
3 2
2 2
7 1
9 2
4 3
1 8
4 5
8 2
7 7

output:

1111111111111111111111111111111111111111111110011111101010001101111

result:

wrong answer 1st words differ - expected: '111111111111111111111111111111...1111111110010101101000101101101', found: '111111111111111111111111111111...1111111110011111101010001101111'