QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#747139#8646. Card Collection275307894a0 3ms38740kbC++144.8kb2024-11-14 16:26:162024-11-14 16:26:17

Judging History

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

  • [2024-11-14 16:26:17]
  • 评测
  • 测评结果:0
  • 用时:3ms
  • 内存:38740kb
  • [2024-11-14 16:26:16]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=2e5+5,M=N*4+5,K=1000+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(28382);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n,m,A[N],B[N],X[N],Y[N];
int flag[N];
struct ST{
	int mx[20][N],mi[20][N];
	void init(int *A){
		copy(A+1,A+n+1,mx[0]+1);copy(A+1,A+n+1,mi[0]+1);
		for(int i=1;(1<<i)<=n;i++){
			for(int j=1;j+(1<<i)-1<=n;j++){
				mx[i][j]=max(mx[i-1][j],mx[i-1][j+(1<<i-1)]);
				mi[i][j]=min(mi[i-1][j],mi[i-1][j+(1<<i-1)]);
			}
		}
	}
	int qrymin(int x,int y){
		int d=__lg(y-x+1);return min(mi[d][x],mi[d][y-(1<<d)+1]);
	}
	int qrymax(int x,int y){
		int d=__lg(y-x+1);return max(mx[d][x],mx[d][y-(1<<d)+1]);
	}
}a,b;
int pa[N],pb[N];
unordered_map<ll,vector<int> > f;
using node=pii;
node operator +(const node &A,const node &B){
	static int C[4];
	C[0]=A.fi;C[1]=A.se;C[2]=B.fi;C[3]=B.se;
	sort(C,C+4);
	return make_pair(C[0],C[1]);
}
vector<pii> Q[N];
node w1[N],w2[N];
namespace bit{
	node f[N];
	void clr(){for(int i=1;i<=n;i++) f[i]=node(INF,INF);}
	void add(int x,node y){while(x<=n) f[x]=f[x]+y,x+=x&-x;}
	node qry(int x){node ans=node(INF,INF);while(x) ans=ans+f[x],x-=x&-x;return ans;}
}
vector<int> S[N];
bool qry(int vx,int vy,node w1,node w2){

	auto check3=[&](int x,int y){
		if(x>y) return true;
		return (a.qrymax(x,y)>=vx||b.qrymin(x,y)<=vy)&&(a.qrymin(x,y)<=vx||b.qrymax(x,y)>=vy);
	};
	auto it=f.find(1ll*vx*n+vy);
	if(it!=f.end()){
		for(int i:it->se) if(A[i]==vx&&B[i]==vy&&check3(1,i-1)&&check3(i+1,n)) return true;
	}

	auto check1=[&](int x,int y){
		if(x>y) return true;
		return !(a.qrymax(x,y)<vx&&b.qrymin(x,y)>vy);
	};
	int i1=pa[vx];
	int d1=n+2,lim1;
	for(int i:{w1.fi,w1.se}) if(1<=i&&i<=n&&A[i]>=vx&&B[i]<=vy&&check1(1,i-1)){d1=i;break;}
	lim1=max(i1,d1+1);
	for(int i=17;~i;i--) if(lim1+(1<<i)-1<=n&&!check1(d1+1,lim1+(1<<i)-1)) lim1+=(1<<i);
	
	auto check2=[&](int x,int y){
		if(x>y) return true;
		return !(a.qrymin(x,y)>vx&&b.qrymax(x,y)<vy);
	};
	int i2=pb[vy];
	int d2=-1,lim2;
	for(int i:{-w2.fi,-w2.se}) if(1<=i&&i<=n&&A[i]<=vx&&B[i]>=vy&&check2(i+1,n)){d2=i;break;}
	lim2=min(i2,d2-1);
	for(int i=17;~i;i--) if(lim1-(1<<i)+1>0&&!check2(lim2-(1<<i)+1,d2-1)) lim2-=(1<<i);

	if(d1>=i1&&d2<=i2&&d1+1==d2) return true;
	if(d1>=i1&&d1+1<=lim2) return true;
	if(d2<=i2&&d2-1>=lim1) return true;
	return lim1+1<=lim2;
}
void build(){
	for(int i=n;i;i--) pa[A[i]]=i;for(int i=1;i<=n;i++) pb[B[i]]=i;	
	a.init(A);b.init(B);
	f.clear();
	for(int i=1;i<=n;i++) f[1ll*A[i]*n+B[i]].push_back(i);
	for(int i=1;i<=n;i++) S[i].clear(),Q[i].clear();
	for(int i=1;i<=n;i++) S[A[i]].push_back(i);
	for(int i=1;i<=n;i++) if(1<=X[i]&&X[i]<=n&&1<=Y[i]&&Y[i]<=n) Q[X[i]].emplace_back(Y[i],i);
	bit::clr();
	for(int i=1;i<=n;i++){
		for(int j:S[i]) bit::add(n-B[j]+1,node(-j,INF));
		for(auto [x,y]:Q[i]) w2[y]=bit::qry(n-x+1);
	}
	bit::clr();
	for(int i=n;i;i--){
		for(int j:S[i]) bit::add(B[j],node(j,INF));
		for(auto [x,y]:Q[i]) w1[y]=bit::qry(x);
	}

	for(int i=1;i<=m;i++)if(1<=X[i]&&X[i]<=n&&1<=Y[i]&&Y[i]<=n) flag[i]|=qry(X[i],Y[i],w1[i],w2[i]);
}
int na[N],nb[N];
void Solve(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d%d",&A[i],&B[i]);
	copy(A+1,A+n+1,na+1);sort(na+1,na+n+1);
	copy(B+1,B+n+1,nb+1);sort(nb+1,nb+n+1);
	for(int i=1;i<=n;i++) A[i]=LB(na+1,na+n+1,A[i])-na;
	for(int i=1;i<=n;i++) B[i]=LB(nb+1,nb+n+1,B[i])-nb;
	for(int i=1;i<=m;i++){
		scanf("%d%d",&X[i],&Y[i]);
		int nx=LB(na+1,na+n+1,X[i])-na,ny=LB(nb+1,nb+n+1,Y[i])-nb;
		if(na[nx]==X[i]&&nb[ny]==Y[i]) X[i]=nx,Y[i]=ny;
		else X[i]=Y[i]=-1;
	}
	build();
	reverse(A+1,A+n+1);reverse(B+1,B+n+1);
	build();
	for(int i=1;i<=n;i++) A[i]=n-A[i]+1,B[i]=n-B[i]+1;
	for(int i=1;i<=m;i++) X[i]=n-X[i]+1,Y[i]=n-Y[i]+1;
	build();
	reverse(A+1,A+n+1);reverse(B+1,B+n+1);
	build();
	for(int i=1;i<=m;i++) if(flag[i]) printf("%d ",i);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 11
Accepted
time: 3ms
memory: 34596kb

input:

2 10
171631799 561094698
171631799 867698918
126573648 561094698
171631799 867698918
171631799 561094698
126573648 561094698
126573648 561094698
171631799 561094698
126573648 561094698
126573648 561094698
126573648 561094698
171631799 561094698

output:

2 3 6 10 

result:

ok 4 number(s): "2 3 6 10"

Test #2:

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

input:

3 10
713180371 43103927
713180371 136832929
853543805 251852293
892623928 251852293
713180371 136832929
713180371 43103927
853543805 43103927
892623928 136832929
713180371 43103927
853543805 43103927
892623928 136832929
713180371 43103927
892623928 251852293

output:

2 3 6 9 

result:

ok 4 number(s): "2 3 6 9"

Test #3:

score: 0
Wrong Answer
time: 3ms
memory: 38740kb

input:

4 10
254412080 855555783
254412080 534954259
610506813 184822793
804271098 233942602
804271098 233942602
536633825 184822793
254412080 855555783
804271098 233942602
536633825 233942602
254412080 855555783
804271098 534954259
610506813 534954259
536633825 184822793
536633825 855555783

output:

1 3 4 6 

result:

wrong answer Answer contains longer sequence [length = 6], but output contains 4 elements

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%