QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136698#238. Distinct ValuesRd_rainydays#100 ✓272ms12632kbC++201.7kb2023-08-09 10:13:162023-08-09 10:13:20

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-09 10:13:20]
  • 评测
  • 测评结果:100
  • 用时:272ms
  • 内存:12632kb
  • [2023-08-09 10:13:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define REP(i,a,b) for(int i=(a),i##_end_=(b);i<i##_end_;++i)

static const int M=100003;

int T,n,m;
vector<int>Q[M];
priority_queue<int>PQ,Del;
int Pos[M],A[M];
int MN[M<<2];

#define lp p<<1
#define rp p<<1|1
#define lson l,m,lp
#define rson m+1,r,rp

void Clear(int l,int r,int p){
  MN[p]=0;
  if(l==r)return;
  int m=l+r>>1;
  Clear(lson);
  Clear(rson);
}
void Modify(int l,int r,int p,int x,int y){
  if(l==r){
    MN[p]=y;
    return;
  }
  int m=l+r>>1;
  if(x<=m)Modify(lson,x,y);
  else Modify(rson,x,y);
  MN[p]=min(MN[lp],MN[rp]);
}
int Query(int l,int r,int p,int x){
  if(l==r)return l;
  int m=l+r>>1;
  //cerr<<l<<','<<r<<','<<MN[lp]<<endl;
  if(MN[lp]<x)return Query(lson,x);
  else return Query(rson,x);
}
int main(){
  scanf("%d",&T);
  while(T--){
    scanf("%d%d",&n,&m);
    REP(i,1,n+1)Q[i].clear();


    REP(i,0,m){
      int l,r;
      scanf("%d%d",&l,&r);
      Q[l].push_back(-l);
      Q[r+1].push_back(l);
    }

    while(!PQ.empty())PQ.pop();
    while(!Del.empty())Del.pop();
    Clear(1,n,1);

    //cout<<"**"<<endl;
    REP(i,1,n+1){
      for(auto x:Q[i]){
        if(x<0)PQ.push(x);
        else Del.push(-x);
      }
      while(!PQ.empty() && !Del.empty() && PQ.top()==Del.top())
        PQ.pop(),Del.pop();
      if(!PQ.empty())
        Pos[i]=-PQ.top();
      else Pos[i]=i;
    }
    //REP(i,1,n+1)printf("%d%c",Pos[i]," \n"[i==n]);
    //mex(A[Pos[i]]~A[i-1])
    REP(i,1,n+1){
      //cout<<i<<":"<<endl;
      if(Pos[i]==i)A[i]=1;
      else A[i]=Query(1,n,1,Pos[i]);
      Modify(1,n,1,A[i],i);
    }
    REP(i,1,n+1)printf("%d%c",A[i]," \n"[i==n]);
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 272ms
memory: 12632kb

input:

11116
10 2
5 5
5 6
10 1
7 10
10 1
2 6
10 1
2 5
10 1
6 7
10 2
8 9
7 10
10 2
1 4
6 10
10 4
8 8
10 10
3 6
1 5
10 3
8 8
10 10
8 10
10 4
6 10
1 5
2 6
1 2
10 3
4 4
4 8
4 8
10 4
1 5
1 2
5 5
2 4
10 4
2 5
9 10
6 7
2 4
10 1
5 6
10 4
10 10
8 10
2 5
10 10
10 1
1 2
10 4
7 8
5 6
7 9
10 10
10 4
3 7
6 6
8 10
3 4
10...

output:

1 1 1 1 1 2 1 1 1 1
1 1 1 1 1 1 1 2 3 4
1 1 2 3 4 5 1 1 1 1
1 1 2 3 4 1 1 1 1 1
1 1 1 1 1 1 2 1 1 1
1 1 1 1 1 1 1 2 3 4
1 2 3 4 1 1 2 3 4 5
1 2 3 4 5 1 1 1 1 1
1 1 1 1 1 1 1 1 2 3
1 2 3 4 5 1 2 3 4 5
1 1 1 1 2 3 4 5 1 1
1 2 3 4 5 1 1 1 1 1
1 1 2 3 4 1 2 1 1 2
1 1 1 1 1 2 1 1 1 1
1 1 2 3 4 1 1 1 2 3
...

result:

ok 11116 lines