QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#743966#2743. Seats_CLY_0 ✓0ms0kbC++172.8kb2024-11-13 20:27:182024-11-13 20:27:24

Judging History

This is a historical verdict posted at 2024-11-13 20:27:24.

  • [2024-11-13 23:14:02]
  • 管理员手动重测本题所有提交记录
  • Verdict: 100
  • Time: 2034ms
  • Memory: 92752kb
  • [2024-11-13 20:27:24]
  • Judged
  • Verdict: 0
  • Time: 0ms
  • Memory: 0kb
  • [2024-11-13 20:27:18]
  • Submitted

answer

#include "seats.h"
#include <bits/stdc++.h>
using namespace std;
inline long long read(){
    long long x=0; char ch; bool f=0;
    while(((ch=getchar())<'0'||ch>'9')&&ch!='-') ;
    if(ch=='-') f=1;
    else x=ch^48;
    while((ch=getchar())>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48);
    return f?-x:x;
}
const int N=3e6+55;
const int dx[4]={-1,-1,0,0};
const int dy[4]={-1,0,-1,0};
int n,m,q;
struct POS{
	int x,y;
	bool operator<(const POS &t)const{
		if(x^t.x) return x<t.x;
		return y<t.y;
	}
}s[N];
int a[N];
int id(int x,int y){
	return x*(m+2)+y+1;
}
struct tr{
	struct tree{
		long long mn,cnt,bz;
	}t[N<<2];
	#define ls (p<<1)
	#define rs (p<<1|1)
	void up(int p){
		t[p].mn=min(t[ls].mn,t[rs].mn);
		t[p].cnt=(t[p].mn==t[ls].mn)*t[ls].cnt+(t[p].mn==t[rs].mn)*t[rs].cnt;
	}
	void cg(int p,long long v){
		t[p].bz+=v,t[p].mn+=v;
	}
	void down(int p){
		if(t[p].bz){
			cg(ls,t[p].bz),cg(rs,t[p].bz),t[p].bz=0;
		}
	}
	void build(int p,int l,int r){
		t[p].mn=0,t[p].cnt=r-l+1;
		if(l==r) return;
		int mid=(l+r)/2;
		build(ls,l,mid),build(rs,mid+1,r);
	}
	void ad(int p,int st,int en,int l,int r,long long v){
		if(st>en||r<st||en<l) return;
		if(st<=l&&r<=en){
			cg(p,v); return;
		}
		int mid=(l+r)/2;
		down(p);
		if(st<=mid) ad(ls,st,en,l,mid,v);
		if(mid<en) ad(rs,st,en,mid+1,r,v);
		up(p);
	}
	int ask(){
		return (t[1].mn==4)*t[1].cnt;
	}
	#undef ls
	#undef rs
}T;
int p[6];
void ins(int x,int y,int v){
	for(int i=0;i<4;i++) p[i]=a[id(x+dx[i],y+dy[i])];
	sort(p,p+4);
	T.ad(1,p[0],p[1]-1,1,n*m,v);
	T.ad(1,p[2],p[3]-1,1,n*m,v);
}
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C){
	n=H,m=W;
	for(int i=1;i<=n*m;i++){
		int x=R[i-1],y=C[i-1]; x++,y++;
		s[i]={x,y};
		a[id(x,y)]=i;
	}
	T.build(1,1,n*m);
	for(int i=0;i<=n+1;i++){
		for(int j=0;j<=m+1;j++){
			if(!i||!j||i==n+1||j==m+1) a[id(i,j)]=n*m+1;
		}
	}
	for(int i=1;i<=n+1;i++){
		for(int j=1;j<=m+1;j++){
			ins(i,j,1);
		}
	}
}
int swap_seats(int t1,int t2){
	t1++,t2++;
	vector<POS> tp,p; p.clear(),tp.clear();
	tp.push_back({s[t1].x,s[t1].y});
	tp.push_back({s[t1].x,s[t1].y+1});
	tp.push_back({s[t1].x+1,s[t1].y});
	tp.push_back({s[t1].x+1,s[t1].y+1});
	tp.push_back({s[t2].x,s[t2].y});
	tp.push_back({s[t2].x,s[t2].y+1});
	tp.push_back({s[t2].x+1,s[t2].y});
	tp.push_back({s[t2].x+1,s[t2].y+1});
	sort(tp.begin(),tp.end());
	for(auto [x,y]:tp){
		if(!p.size()||p.back().x!=x||p.back().y!=y) p.push_back({x,y});
	}
	for(auto [x,y]:p){
		ins(x,y,-1);
	}
	swap(a[id(s[t1].x,s[t1].y)],a[id(s[t2].x,s[t2].y)]);
	swap(s[t1],s[t2]); 
//		for(int i=1;i<=n*m;i++)cout<<s[i].x<<" "<<s[i].y<<"!!\n";
	for(auto [x,y]:p){
		ins(x,y,1);
	}
//		cout<<T.t[1].mn<<" "<<T.t[1].cnt<<"??\n";
//		cout<<T.ask()<<"!\n";
	return T.ask();
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

3 3 5000
2 2
1 2
0 2
0 1
0 0
2 1
1 1
1 0
2 0
6 0
5 7
6 4
3 2
0 2
0 2
7 0
7 0
3 2
3 6
0 2
3 5
2 6
2 0
8 6
0 6
1 3
1 8
8 1
4 2
1 8
2 5
1 3
7 0
6 5
6 3
2 8
8 2
1 3
8 5
6 3
8 0
4 8
6 8
7 8
4 3
3 6
5 0
8 5
1 7
2 6
1 2
5 4
5 1
7 6
8 4
7 3
6 8
8 3
0 3
6 3
0 8
0 5
7 2
0 3
7 5
4 5
3 5
1 0
0 8
7 0
2 5
5 8
7 4...

output:

Unauthorized output

result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Runtime Error

Test #33:

score: 0
Runtime Error

input:

101 101 5000
0 0
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
0 10
0 11
0 12
0 13
0 14
0 15
0 16
0 17
0 18
0 19
0 20
0 21
0 22
0 23
0 24
0 25
0 26
0 27
0 28
0 29
0 30
0 31
0 32
0 33
0 34
0 35
0 36
0 37
0 38
0 39
0 40
0 41
0 42
0 43
0 44
0 45
0 46
0 47
0 48
0 49
0 50
0 51
0 52
0 53
0 54
0 55
0 56
0 57
0 58
0 ...

output:

Unauthorized output

result:


Subtask #5:

score: 0
Runtime Error

Test #44:

score: 0
Runtime Error

input:

1 3 50000
0 1
0 2
0 0
0 2
2 0
2 1
0 1
1 0
0 1
1 2
1 2
1 2
0 2
1 0
0 2
2 0
1 2
2 1
2 0
0 1
0 2
1 2
1 0
1 0
1 2
0 1
1 0
0 2
0 2
2 1
0 2
1 0
1 2
2 1
2 1
1 2
0 1
1 2
0 1
0 2
1 2
0 2
2 1
2 0
1 2
1 0
1 0
2 1
1 0
1 0
2 1
1 2
0 2
2 0
1 0
2 0
0 2
1 0
0 2
1 2
2 1
0 1
0 2
1 0
2 1
2 0
1 2
0 1
2 0
2 1
2 0
0 2
1 ...

output:

Unauthorized output

result:


Subtask #6:

score: 0
Skipped

Dependency #1:

0%