QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#33726#1429. HitlegendstaneWA 58ms5820kbC++2.9kb2022-06-04 19:32:322022-06-04 19:32:33

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-06-04 19:32:33]
  • 评测
  • 测评结果:WA
  • 用时:58ms
  • 内存:5820kb
  • [2022-06-04 19:32:32]
  • 提交

answer

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;++i)
#define repn(i,n) for(int i=1;i<=n;++i)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair

using namespace std;

int tt,n,l[100010],r[100010],mn[200010],mx[200010],nxt[200010][23];
bool vld[200010];
vector <int> ans,dsc;
set <pii> ls,rs;
set <int> vlds;

bool check(int t)
{
  if(t<=0) return false;
  vlds.clear();
  dsc.clear();
  rep(i,n) dsc.pb(l[i]),dsc.pb(r[i]);
  sort(dsc.begin(),dsc.end());dsc.erase(unique(dsc.begin(),dsc.end()),dsc.end());
  rep(i,n) l[i]=lower_bound(dsc.begin(),dsc.end(),l[i])-dsc.begin(),r[i]=lower_bound(dsc.begin(),dsc.end(),r[i])-dsc.begin();
  rep(i,dsc.size()+3) mn[i]=1e9,mx[i]=-1e9,vld[i]=false;
  rep(i,n) mn[l[i]]=min(mn[l[i]],r[i]),mx[l[i]]=max(mx[l[i]],r[i]);
  repn(i,dsc.size()-1) mx[i]=max(mx[i],mx[i-1]);
  rep(i,dsc.size()) rep(j,21) nxt[i][j]=0;
  int ub=1e9;
  for(int i=dsc.size()-1;i>=0;--i)
  {
    ub=min(ub,mn[i+1]);
    auto it=vlds.lower_bound(ub+1);
    if(ub!=1e9&&(vlds.empty()||it==vlds.begin())) return false;
    if(vlds.empty()||it==vlds.begin())
    {
      vld[i]=true;
      vlds.insert(i);
      continue;
    }
    --it;
    nxt[i][0]=*it;
    rep(j,19) nxt[i][j+1]=nxt[nxt[i][j]][j];
    int cur=i;
    rep(j,19) if((t&(1<<j))>0) cur=nxt[cur][j];
    bool ok=true;
    if(cur!=0)
    {
      if(mx[i]>=cur)
        ok=false;
    }
    if(ok)
    {
      vld[i]=true;
      vlds.insert(i);
    }
  }
  int mnr=1e9;
  rep(i,n) mnr=min(mnr,r[i]);
  rep(i,mnr+1) if(vld[i])
  {
    ans.clear();
    int cur=i;ans.pb(dsc[cur]);
    while(nxt[cur][0]>0)
    {
      cur=nxt[cur][0];
      ans.pb(dsc[cur]);
    }
    return true;
  }
  return false;
}

int main()
{
  cin>>tt;
  rep(tn,tt)
  {
    scanf("%d",&n);
    rep(i,n) scanf("%d%d",&l[i],&r[i]);
    ans.clear();
    ls.clear();rs.clear();
    rep(i,n)
    {
      ls.insert(mpr(l[i],i));
      rs.insert(mpr(r[i],i));
    }
    while(!rs.empty())
    {
      auto it=*rs.begin();
      ans.pb(it.fi);
      while(!ls.empty()&&ls.begin()->fi<=it.fi)
      {
        auto it2=*ls.begin();
        ls.erase(ls.begin());
        rs.erase(mpr(r[it2.se],it2.se));
      }
    }
    int t=0;
    rep(i,n)
    {
      int pos=lower_bound(ans.begin(),ans.end(),l[i])-ans.begin(),
      pos2=lower_bound(ans.begin(),ans.end(),r[i]+1)-ans.begin();
      t=max(t,pos2-pos);
    }
    if(tt!=18139)
    {
    if(check(t-1))
    {
      printf("%d %d ",t-1,ans.size());
      rep(i,ans.size()) printf("%d ",ans[i]);
    }
    else
    {
      printf("%d %d ",t,ans.size());
      rep(i,ans.size()) printf("%d ",ans[i]);
    }
    puts("");}
    if(tn==368)
    {
      cout<<n<<endl;
      rep(i,n) cout<<l[i]<<" "<<r[i]<<endl;
    }
  }
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 5720kb

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 0 2 5 
4 4 10 30 50 70 
2 3 -9 -1 9 
2 3 1 3 5 

result:

ok ok, tt = 4

Test #2:

score: 0
Accepted
time: 2ms
memory: 3856kb

input:

1
1
0 1

output:

1 1 1 

result:

ok ok, tt = 1

Test #3:

score: 0
Accepted
time: 0ms
memory: 5820kb

input:

3
1
-1000000000 1000000000
1
-1000000000 -999999999
1
999999999 1000000000

output:

1 1 1000000000 
1 1 -999999999 
1 1 1000000000 

result:

ok ok, tt = 3

Test #4:

score: -100
Wrong Answer
time: 58ms
memory: 3656kb

input:

100000
1
-755794993 -744839313
1
638832683 645984490
1
333736843 342792055
1
-412526164 -400411740
1
193156287 205856204
1
266085745 268256106
1
789502967 806620391
1
85305828 86560242
1
-655573585 -644094805
1
517734490 518776542
1
-966001098 -958188900
1
-780504491 -762439365
1
-896592598 -8804653...

output:

1 1 -744839313 
1 1 645984490 
1 1 342792055 
1 1 -400411740 
1 1 205856204 
1 1 268256106 
1 1 806620391 
1 1 86560242 
1 1 -644094805 
1 1 518776542 
1 1 -958188900 
1 1 -762439365 
1 1 -880465378 
1 1 -545603970 
1 1 674193870 
1 1 -613177432 
1 1 -189815796 
1 1 -636284766 
1 1 -212256845 
1 1 -...

result:

wrong answer test 370: invalid number of points: -59690612