QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#502565#8711. TilesScapegoat_DawnCompile Error//C++143.1kb2024-08-03 09:45:102024-08-03 09:45:10

Judging History

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

  • [2024-08-03 09:45:10]
  • 评测
  • [2024-08-03 09:45:10]
  • 提交

answer

#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 int long long
//#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
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 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;
int x[maxn],y[maxn],t[maxn],tx[maxn],lx;

vector<pii>buc[maxn];

struct info{
	int l,r;
	bool f[2][2];
	info(){
		l=r=-1;
		memset(f,0,sizeof f);
	}
};

// 

info gen(int l,int r,int y){
	info t;
	if(!y){
		For(i,0,1) t.f[i][i]=1;
		t.l=-1;
		t.r=-1;
	}else{
		t.l=l,t.r=r;
		For(i,0,1) For(j,0,1) t.f[i][j]=((i==j)==((r-l+1)%2==0));
	}
	return t;
}

info merge(info a,info b){
	if(a.l==-1) return b;
	if(b.l==-1) return a;
	info c;
	c.l=a.l,c.r=b.r;
	For(x,0,1)
		For(y,0,1) if(a.f[x][y] && (!y||a.r+1==b.l))
			For(z,0,1)
				if(b.f[y][z]) c.f[x][z]=1;
	return c;
}

struct segt{
	info tr[maxn<<2][2];
	bool rev[maxn<<2];
	void up(int p){
		For(i,0,1) tr[p][i]=merge(tr[p<<1][i],tr[p<<1|1][i]);
	}
	void pt(int p){
		rev[p]^=1;
		swap(tr[p][0],tr[p][1]);
	}
	void down(int p){
		if(rev[p]){
			pt(p<<1),pt(p<<1|1);
			rev[p]=0;
		}
	}
	void mdf(int p,int l,int r,int ql,int qr){
		if(l>=ql&&r<=qr)return pt(p);
		int mid=l+r>>1; down(p);
		if(ql<=mid) mdf(p<<1,l,mid,ql,qr);
		if(qr>mid) mdf(p<<1|1,mid+1,r,ql,qr);
		up(p);
	}
	void build(int p,int l,int r){
	//	cout<<"build "<<p<<" "<<l<<" "<<r<<"\n";
		if(l==r){
			For(i,0,1) tr[p][i]=gen(t[l],t[l+1]-1,i);
			return;
		}
		int mid=l+r>>1;
		build(p<<1,l,mid);
		build(p<<1|1,mid+1,r);
		up(p);
	}
	bool chk(){
		return tr[1][0].f[0][0];
	}
	bool chk0(){
		return tr[1][0].l==-1;
	}
}T[2];

signed main()
{
	n=read(),m=read(); int mm=m; m=0;
	For(i,1,n)x[i]=read(),y[i]=read(),t[++m]=y[i],tx[++lx]=x[i];
	sort(t+1,t+m+1); sort(tx+1,tx+lx+1);
	m=unique(t+1,t+m+1)-t-1,lx=unique(tx+1,tx+lx+1)-tx-1;
	For(i,1,n){
		x[i]=lower_bound(tx+1,tx+lx+1,x[i])-tx;
		y[i]=lower_bound(t+1,t+m+1,y[i])-t;
	}
	For(i,1,n){
		int j=i%n+1;
		if(x[i]==x[j]) buc[x[i]].pb(mkp(min(y[i],y[j]),max(y[i],y[j])));
	}
	//cout<<"---\n";
	T[0].build(1,1,m-1);
	T[1]=T[0];
	int o=0;
	int res=tx[1];
	tx[lx+1]=2e9;
	For(i,1,lx){
	//	cout<<"i: "<<i<<"\n";
		for(auto [l,r]:buc[i]) T[o].mdf(1,1,m-1,l,r-1);
		if(!T[o].chk()){
		if(T[o].chk0()) res=max(res,tx[i]);
		
		int tt[2]={tx[i+1],tx[i+1]-1};
		if((tt[0]-tx[i])%2) swap(tt[0],tt[1]);
		
		if((tx[i+1]-tx[i])>=2){
			if(!T[!o].chk()){
				cout<<res;
				exit(0);
			}
		}
		
		if(T[o].chk0() && tt[1]>=tx[i]) res=max(res,tt[1]);
		if(T[!o].chk0() && tt[0]>=tx[i]) res=max(res,tt[0]);
		
		if((tx[i+1]-tx[i])%2){
			o^=1;
		}
	}
	res=min(res,mm);
	cout<<res;
	return 0;
}

詳細信息

answer.code: In function ‘int main()’:
answer.code:133:26: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
  133 |                 for(auto [l,r]:buc[i]) T[o].mdf(1,1,m-1,l,r-1);
      |                          ^
answer.code:157:2: error: expected ‘}’ at end of input
  157 | }
      |  ^
answer.code:112:1: note: to match this ‘{’
  112 | {
      | ^