QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#53213#1429. HitCrysflyWA 3ms3556kbC++112.3kb2022-10-04 20:17:182022-10-04 20:17:21

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-04 20:17:21]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3556kb
  • [2022-10-04 20:17:18]
  • 提交

answer

// what is matter? never mind.
#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)
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 600005
#define inf 0x3f3f3f3f

/*
得出一个答案的界:check(t-1 or t)
现在要 check(t) 
设 f[v] 放了 v,>=v 的放了若干个点,是否所有 r>=v 的区间都 ok
放一个点会干掉一些
next(v) 表示选 v,next(v) 不会漏掉区间。
判断走 next t 次是否合法即可。 
*/

int m,n,t,b[maxn];
void ADD(int x){b[++t]=x-1,b[++t]=x,b[++t]=x+1;}
int V(int x){return lower_bound(b+1,b+t+1,x)-b;}
struct node{
	int l,r;
	bool operator <(const node&b)const{return r!=b.r?r<b.r:l>b.l;}
}a[maxn];
int res[maxn],tp;
int mn[maxn],mx[maxn],ok[maxn];
int fa[maxn][20];
int q[maxn],hd,tl;
void work()
{
	n=read(),t=0;tp=0;m=0;
	For(i,1,n)a[i].l=read(),a[i].r=read(),ADD(a[i].l),ADD(a[i].r);
	b[++t]=inf,b[++t]=-inf,sort(b+1,b+t+1),t=unique(b+1,b+t+1)-b-1;
	For(i,1,n)a[i].l=V(a[i].l),a[i].r=V(a[i].r);
	sort(a+1,a+n+1);
	int R=-1;
	For(i,1,n){
		if(R<a[i].l)R=a[i].r,res[++tp]=R;
		int qwq=(lower_bound(res+1,res+tp+1,a[i].l)-res);
		m=max(m,tp-qwq);
	}
	if(m==1){
		cout<<m<<' '<<tp<<" ";
		For(i,1,tp)cout<<res[i]<<" \n"[i==tp];
		return;
	}
	For(i,0,t+1)mn[i]=inf,mx[i]=-inf,ok[i]=0;
	For(i,1,n){
		mn[a[i].l]=min(mn[a[i].l],a[i].r);
		mx[a[i].l]=max(mx[a[i].l],a[i].r);
	}
	For(i,2,t)mx[i]=max(mx[i],mx[i-1]);
	Rep(i,t-1,1)mn[i]=min(mn[i],mn[i+1]);
	ok[t]=1;
	For(i,0,19)fa[t][i]=t;
	q[hd=tl=1]=t;
	Rep(i,t-1,1){
		while(hd<=tl && q[hd]>mn[i+1]) ++hd;
		if(hd>tl)continue;
		int u=q[hd];
		fa[i][0]=u;
		Rep(j,19,0)
			if((m-2)>>j&1) u=fa[u][j];
		if(!u || u<=mx[i]) continue;
		q[++tl]=i;
		ok[i]=1;
		For(j,0,19)
			fa[i][j]=fa[fa[i][j-1]][j-1];
	}
	if(ok[1]){
		--m;tp=0;
		int u=fa[1][0];
		while(u<t)res[++tp]=u,u=fa[u][0];
	}
	cout<<m<<' '<<tp<<" ";
	For(i,1,tp)cout<<res[i]<<" \n"[i==tp];
}

signed main()
{
	int T=read();
	while(T--)work();
	return 0;
}

详细

Test #1:

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

input:

4
4
0 1
2 3
4 5
3 5
5
0 70
0 10
20 30
40 50
60 70
8
-1 7
-2 -1
-9 -7
-8 9
-9 -7
-2 4
-7 4
3 9
5
0 1
0 2
2 3
3 5
4 5

output:

1 3 4 6 8
3 4 6 12 18 24
2 3 5 9 18
1 3 4 6 8

result:

wrong answer test 1: segment [0, 1] does not contain any points