QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#439653#8711. TilesA_zjzj0 55ms45856kbC++174.8kb2024-06-12 15:35:442024-06-12 15:35:44

Judging History

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

  • [2024-06-12 15:35:44]
  • 评测
  • 测评结果:0
  • 用时:55ms
  • 内存:45856kb
  • [2024-06-12 15:35:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned ll;
const int N=2e5+10,M=N*2;
int n;
struct node{
	int x,y;
}a[N];
ll cross(node a,node b){
	return 1ll*a.x*b.y-1ll*a.y*b.x;
}
vector<int>nx,ny;
using vec=array<int,4>;
#ifdef DEBUG
ostream& operator << (ostream &out,vec a){
	out<<'[';
	for(auto x:a)out<<x<<',';
	return out<<']';
}
#endif
namespace SGT1{
	const vec I={0,1,2,3};
	vec operator + (const vec &a,const vec &b){
		static vec c;
		for(int i=0;i<4;i++)c[i]=a[i]+b[i];
		return c;
	}
	vec merge(const vec &a,const vec &b){
		static vec c;
		for(int i=0;i<4;i++)c[i]=b[a[i]];
		return c;
	}
	vec Merge(const vec &a,const vec &b){
		static vec c;
		c.fill(0);
		for(int i=0;i<4;i++)c[b[i]]+=a[i];
		return c;
	}
	vec t[M<<2],laz[M<<2];
	void pushup(int rt){
		t[rt]=t[rt<<1]+t[rt<<1|1];
	}
	void pushlaz(int rt,vec x){
		t[rt]=Merge(t[rt],x);
		laz[rt]=merge(laz[rt],x);
	}
	void pushdown(int rt){
		if(laz[rt]!=I){
			pushlaz(rt<<1,laz[rt]);
			pushlaz(rt<<1|1,laz[rt]);
			laz[rt]=I;
		}
	}
	void build(int l=0,int r=ny.size()-2,int rt=1){
		laz[rt]=I;
		if(l==r)return t[rt][0]=ny[l+1]-ny[l],void();
		int mid=(l+r)>>1;
		build(l,mid,rt<<1);
		build(mid+1,r,rt<<1|1);
		pushup(rt);
	}
	void update(int L,int R,vec x,int l=0,int r=ny.size()-2,int rt=1){
		// if(rt==1)debug("update",L,R,x);
		if(L<=l&&r<=R)return pushlaz(rt,x);
		int mid=(l+r)>>1;
		pushdown(rt);
		if(L<=mid)update(L,R,x,l,mid,rt<<1);
		if(mid<R)update(L,R,x,mid+1,r,rt<<1|1);
		pushup(rt);
	}
	vec query(int L=0,int R=ny.size()-2,int l=0,int r=ny.size()-2,int rt=1){
		if(L<=l&&r<=R)return t[rt];
		int mid=(l+r)>>1;
		pushdown(rt);
		if(R<=mid)return query(L,R,l,mid,rt<<1);
		if(mid<L)return query(L,R,mid+1,r,rt<<1|1);
		return query(L,R,l,mid,rt<<1)+query(L,R,mid+1,r,rt<<1|1);
	}
}
namespace SGT2{
	struct node{
		int st,ed,cnt;
		bool f,g;
	};
	node operator + (const node &a,const node &b){
		if(a.st==-1)return b;
		if(b.st==-1)return a;
		if(a.cnt%2==0)return {a.st,b.ed,a.cnt+b.cnt,a.f&&b.f,a.g&&b.g&&(b.st-a.ed)%2==0};
		else return {a.st,b.ed,a.cnt+b.cnt,a.f&&b.g&&(b.st-a.ed)%2==0,a.g&&b.f};
	}
	node t[M<<2];
	void pushup(int rt){
		t[rt]=t[rt<<1]+t[rt<<1|1];
	}
	void build(int l=0,int r=ny.size()-1,int rt=1){
		t[rt]={-1,-1,0,0,0};
		if(l==r)return;
		int mid=(l+r)>>1;
		build(l,mid,rt<<1);
		build(mid+1,r,rt<<1|1);
	}
	void update(int x,int l=0,int r=ny.size()-1,int rt=1){
		if(l==r){
			if(t[rt].st==-1)t[rt]={ny[l],ny[l],1,1,1};
			else t[rt]={-1,-1,0,0,0};
			return;
		}
		int mid=(l+r)>>1;
		if(x<=mid)update(x,l,mid,rt<<1);
		else update(x,mid+1,r,rt<<1|1);
		pushup(rt);
	}
	bool query(){
		return t[1].f;
	}
}
vector<pair<int,int>>o1[M],o2[M];
void reduce(vector<pair<int,int>>&o){
	sort(all(o));
	int len=-1;
	for(int i=0;i<len;i++){
		if(len==-1||o[len].second!=o[i].first)o[++len]=o[i];
		else o[len].second=o[i].second;
	}
	o.resize(len+1);
}
int main(){
	scanf("%d%*d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a[i].x,&a[i].y);
	}
	if([&](){
		ll s=0;
		for(int i=1;i<=n;i++){
			s+=cross(a[i],a[i%n+1]);
		}
		return s<0;
	}())reverse(a+1,a+1+n);
	for(int i=1;i<=n;i++){
		nx.push_back(a[i].x);
		ny.push_back(a[i].y);
	}
	sort(all(nx)),nx.erase(unique(all(nx)),nx.end());
	sort(all(ny)),ny.erase(unique(all(ny)),ny.end());
	for(int i=1;i<=n;i++){
		a[i].x=lower_bound(all(nx),a[i].x)-nx.begin();
		a[i].y=lower_bound(all(ny),a[i].y)-ny.begin();
	}
	for(int i=1;i<=n;i++){
		int j=i%n+1;
		if(a[i].x!=a[j].x)continue;
		if(a[i].y>a[j].y){
			o1[a[i].x].push_back({a[j].y,a[i].y});
		}else{
			o2[a[i].x].push_back({a[i].y,a[j].y});
		}
	}
	int ans=0;
	SGT1::build();
	SGT2::build();
	// debug(nx,ny);
	for(int i=0;i+1<nx.size();i++){
		if(![&](){
			reduce(o1[i]);
			reduce(o2[i]);
			for(auto [l,r]:o1[i]){
				auto res=SGT1::query(l,r-1);
				SGT1::update(l,r-1,vec({1,1,3,3}));
				SGT2::update(l),SGT2::update(r);
				if((res[2]||res[3])&&!SGT2::query())return 0;
			}
			for(auto [l,r]:o2[i]){
				auto res=SGT1::query(l,r-1);
				if(res[2]||res[3])return 0;
				SGT1::update(l,r-1,vec({0,0,2,2}));
				SGT2::update(l),SGT2::update(r);
			}
			if(!SGT2::query())return 0;
			int d=nx[i+1]-nx[i];
			static vec t={0,3,2,1};
			if(d%2==0)SGT1::update(0,ny.size()-2,t);
			auto res=SGT1::query();
			// debug(i,res);
			if(!res[2]&&!res[3])ans=nx[i+1]-1;
			SGT1::update(0,ny.size()-2,t);
			res=SGT1::query();
			// debug(i,res);
			if(!res[2]&&!res[3])ans=nx[i+1];
			return 1;
		}())break;
	}
	cout<<ans<<endl;
	return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 4
Accepted
time: 8ms
memory: 27328kb

input:

4 3
0 0
0 3
3 3
3 0

output:

0

result:

ok single line: '0'

Test #2:

score: -4
Wrong Answer
time: 0ms
memory: 29036kb

input:

4 999999999
999999999 0
999999999 1000000000
0 1000000000
0 0

output:

0

result:

wrong answer 1st lines differ - expected: '999999998', found: '0'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #32:

score: 0
Wrong Answer
time: 8ms
memory: 27772kb

input:

1551 1000
0 988
2 988
3 988
6 988
6 985
6 982
6 981
6 979
6 978
6 977
6 976
6 975
6 974
6 972
6 970
6 969
6 968
6 966
6 965
6 964
7 964
8 964
8 963
8 961
8 960
10 960
11 960
13 960
16 960
16 959
16 958
16 957
16 954
16 953
16 951
16 950
17 950
18 950
18 948
18 946
18 945
18 944
18 942
18 941
18 939
...

output:

0

result:

wrong answer 1st lines differ - expected: '164', found: '0'

Subtask #4:

score: 0
Wrong Answer

Test #45:

score: 0
Wrong Answer
time: 0ms
memory: 30280kb

input:

14 6
0 1
0 3
2 3
2 4
0 4
0 6
3 6
3 7
4 7
6 7
6 5
3 5
3 2
3 1

output:

0

result:

wrong answer 1st lines differ - expected: '2', found: '0'

Subtask #5:

score: 0
Wrong Answer

Test #89:

score: 22
Accepted
time: 46ms
memory: 31460kb

input:

199996 198506138
31225688 248200160
31225688 248291950
28995282 248291950
28995282 248200160
26764876 248200160
26764876 248291950
24534470 248291950
24534470 248200160
22304064 248200160
22304064 248291950
20073658 248291950
20073658 248200160
17843252 248200160
17843252 248291950
15612846 24829195...

output:

0

result:

ok single line: '0'

Test #90:

score: 0
Accepted
time: 44ms
memory: 31292kb

input:

199996 740789144
48843244 341844840
48843244 342042210
40702704 342042210
40702704 341844840
32562164 341844840
32562164 342042210
24421624 342042210
24421624 341844840
16281084 341844840
16281084 342042210
8140544 342042210
8140544 341450100
16281084 341450100
16281084 341647470
24421624 341647470
...

output:

0

result:

ok single line: '0'

Test #91:

score: -22
Wrong Answer
time: 46ms
memory: 31360kb

input:

199996 198506138
31225684 248200166
31225684 248291956
28995278 248291956
28995278 248200166
26764872 248200166
26764872 248291956
24534466 248291956
24534466 248200166
22304060 248200166
22304060 248291956
20073654 248291956
20073654 248200166
17843248 248200166
17843248 248291956
15612842 24829195...

output:

0

result:

wrong answer 1st lines differ - expected: '198506134', found: '0'

Subtask #6:

score: 0
Wrong Answer

Test #118:

score: 0
Wrong Answer
time: 55ms
memory: 45856kb

input:

200000 1000000000
1000000000 0
999990876 0
999990876 38
999972524 38
999972524 1510
999969180 1510
999969180 3734
999964780 3734
999964780 4138
999960464 4138
999960464 11052
999953728 11052
999953728 24478
999914972 24478
999914972 25892
999909864 25892
999909864 28102
999902920 28102
999902920 301...

output:

0

result:

wrong answer 1st lines differ - expected: '40502', found: '0'

Subtask #7:

score: 0
Skipped

Dependency #1:

0%