QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#672953 | #1429. Hit | Flamire | WA | 0ms | 14000kb | C++17 | 2.6kb | 2024-10-24 20:00:38 | 2024-10-24 20:00:38 |
Judging History
answer
#include <bits/stdc++.h>
#define N 400011
using namespace std;
int t,n,l[N],r[N],m,ned[N],mnl[N];
bool dp[N];int w[N],tow[N][21];
vector<int> vv;
int nxt[N];
int getw(int u,int k)
{
for(int i=18;~i;--i)if(~u&&(k>>i&1))u=tow[u][i];
return u;
}
bool check(int X)
{
// printf("============================check(X:%d)\n",X);
for(int i=1;i<=m+1;++i)nxt[i]=w[i]=-1,dp[i]=0;
for(int i=1;i<=m+1;++i)for(int j=0;j<=18;++j)tow[i][j]=-1;
int lst=0;
for(int i=1;i<=m+1;++i)
{//printf(">>>>>>>>i:%d\n",i);
if(!~ned[i])
{
// printf("<>no pre success\n");
w[i]=tow[i][0]=-1;
for(int j=1;j<=18;++j)tow[i][j]=-1;
dp[i]=1;
while(lst<i)nxt[++lst]=i;
continue;
}
if(!~nxt[ned[i]])return 0;
int u=nxt[ned[i]],v=getw(u,X-1);
if(mnl[i]>v)
{
// printf("<>success w:%d\n",u);
dp[i]=1;
tow[i][0]=w[i]=u;
for(int j=1;j<=18;++j)tow[i][j]=tow[tow[i][j-1]][j-1];
while(lst<i)nxt[++lst]=i;
}
}
// printf("dp:");for(int i=1;i<=m+1;++i)printf("%d ",dp[i]);putchar(10);
// printf("w:");for(int i=1;i<=m+1;++i)printf("%d ",w[i]);putchar(10);
return dp[m+1];
}
int main()
{
scanf("%d",&t);while(t--)
{
scanf("%d",&n);vv.clear();
for(int i=1;i<=n;++i)scanf("%d%d",l+i,r+i),vv.push_back(l[i]),vv.push_back(r[i]),vv.push_back(l[i]-1),vv.push_back(r[i]+1);
// if(t==691)
// {
// printf("%d\n",n);
// for(int i=1;i<=n;++i)printf("%d %d\n",l[i],r[i]);
// }
sort(vv.begin(),vv.end());vv.resize(unique(vv.begin(),vv.end())-vv.begin());
m=vv.size();
for(int i=1;i<=n;++i)
{
l[i]=lower_bound(vv.begin(),vv.end(),l[i])-vv.begin()+1;
r[i]=lower_bound(vv.begin(),vv.end(),r[i])-vv.begin()+1;
}
// printf("new intervals:");for(int i=1;i<=n;++i)printf("[%d,%d] ",l[i],r[i]);putchar(10);
for(int i=0;i<=m+1;++i)ned[i]=-1;
for(int i=1;i<=n;++i)ned[r[i]+1]=max(ned[r[i]+1],l[i]);
for(int i=1;i<=m+1;++i)ned[i]=max(ned[i],ned[i-1]);
for(int i=1;i<=m+1;++i)mnl[i]=1e9;
for(int i=1;i<=n;++i)mnl[r[i]]=min(mnl[r[i]],l[i]);
for(int i=m;i;--i)mnl[i]=min(mnl[i+1],mnl[i]);
// printf("ned:");for(int i=1;i<=m+1;++i)printf("%d ",ned[i]);putchar(10);
// printf("mnl:");for(int i=1;i<=m+1;++i)printf("%d ",mnl[i]);putchar(10);
int L=1,R=n,ans=0;
while(L<=R)
{
int M=L+R>>1;
if(check(M))ans=M,R=M-1;else L=M+1;
}
check(ans);
int tt=w[m+1];
static vector<int> res;res.clear();
while(~tt)
{
res.push_back(vv[tt-1]);
if(res.size()>m)for(;;);
tt=w[tt];
}
reverse(res.begin(),res.end());
printf("%d %d ",ans,(int)res.size());
// for(int x:res)printf("%d ",x);
putchar(10);
}
fclose(stdin);fclose(stdout);return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 14000kb
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 4 2 3 2 3
result:
wrong answer test 1: duplicate coordinate: 4