QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#53216 | #1429. Hit | Crysfly | WA | 1ms | 3548kb | C++11 | 2.3kb | 2022-10-04 20:18:28 | 2022-10-04 20:18:32 |
Judging History
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<<b[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]){
puts("QAQ");
--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<<b[res[i]]<<" \n"[i==tp];
}
signed main()
{
int T=read();
while(T--)work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3548kb
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 1 3 5 3 4 10 30 50 70 2 3 -7 -1 9 1 3 1 3 5
result:
wrong answer test 1: wrong result: declared 1, actual 2