QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#421067 | #238. Distinct Values | ship2077 | 100 ✓ | 141ms | 5220kb | C++14 | 1.1kb | 2024-05-25 11:09:42 | 2024-05-25 11:09:42 |
Judging History
answer
#include<bits/stdc++.h>
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
using namespace std;
constexpr int M=1e5+5,inf=0x3f3f3f3f;
int n,m,l,r,lg,tmp,p[M],tr[M<<2];
int read(){
int x=0;char ch=getchar();
while (!isdigit(ch)) ch=getchar();
while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
return x;
}
void build(int l,int r,int x){
tr[x]=0;if (l==r) return;int mid=l+r>>1;
build(l,mid,ls(x));build(mid+1,r,rs(x));
}
void update(int p,int c,int l=1,int r=n,int x=1){
if (l==r) return tr[x]=c,void();int mid=l+r>>1;
p<=mid?update(p,c,l,mid,ls(x)):update(p,c,mid+1,r,rs(x));tr[x]=min(tr[ls(x)],tr[rs(x)]);
}
int query(int p,int l=1,int r=n,int x=1){
if (l==r) return l; int mid=l+r>>1;
return tr[ls(x)]<=p?query(p,l,mid,ls(x)):query(p,mid+1,r,rs(x));
}
void solve(){
n=read();m=read();
lg=31^__builtin_clz(n);
for (int i=1;i<=n;i++) p[i]=i;
for (int i=1;i<=m;i++) l=read(),r=read(),p[r]=min(p[r],l-1);
for (int i=n-1;i;i--) p[i]=min(p[i],p[i+1]);
build(1,n,1);
for (int i=1,tmp;i<=n;i++)
printf("%d%c",tmp=query(p[i])," \n"[i==n]),update(tmp,i);
}
int main(){int T=read(); while (T--) solve(); return 0;}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 141ms
memory: 5220kb
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