/*
"TLE is like the wind, always by my side"
- Yasuo - 2022 -
*/
#include<bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize("Ofast")
using namespace std;
struct qq
{
int l;
int r;
int x;
};
struct ptval
{
int nr;
int poz;
};
ptval val[100001];
const int inf=INT_MAX;
qq query[100001];
int st[100001];
int finl[100001];
bool placed[100001];
int lazy[400001];
bool cmp (qq a, qq b)
{
if (a.x!=b.x)
return a.x<b.x;
else if (a.l!=b.l)
return a.l<b.l;
else
return a.r<b.r;
}
bool cmp2(ptval a, ptval b)
{
return a.nr>b.nr;
}
void propagate(int parent, int child)
{
lazy[child]=lazy[parent];
}
void lazy_update (int l, int r, int val, int qa, int qb, int x)
{
if (lazy[val]!=-1)
{
if (r!=l)
{
propagate(val,val*2);
propagate(val,val*2+1);
}
lazy[val]=-1;
}
if (l>qb || r<qa)
return;
if (qa<=l && r<=qb)
{
lazy[val]=x;
return;
}
int mid;
mid=(l+r)/2;
if (qa<=mid)
lazy_update(l,mid,val*2,qa,qb,x);
if (qb>mid)
lazy_update(mid+1,r,val*2+1,qa,qb,x);
}
int qry (int l, int r, int val, int qa, int qb)
{
if (qa<=l && r<=qb)
{
return lazy[val];
}
if (lazy[val]!=-1)
{
if (r!=l)
{
propagate(val,val*2);
propagate(val,val*2+1);
}
lazy[val]=-1;
}
if (r<qa || l>qb)
return inf;
int mid,ans;
mid=(l+r)/2;
ans=inf;
if (qa<=mid)
ans=min(ans,qry(l,mid,val*2,qa,qb));
if (qb>mid)
ans=min(ans,qry(mid+1,r,val*2+1,qa,qb));
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie();
cout.tie();
int n,q,i,j,t,next,nextsmall;
bool ok;
ok=true;
cin >> n >> q;
for (i=1; i<=q; i++)
{
cin >> query[i].l >> query[i].r >> query[i].x;
}
sort(query+1,query+1+q,cmp);
t=0;
for (j=1; j<=q; j++)
{
if (query[j].x!=query[st[t]].x || (query[j].r<query[st[t]].l || query[j].l>query[st[t]].r))
{
t++;
st[t]=j;
}
else
{
query[st[t]].l=min(query[st[t]].l,query[j].l);
query[st[t]].r=max(query[st[t]].r,query[j].r);
}
}
q=t;
while (t>0)
{
if (query[st[t]].x==query[st[t+1]].x && t!=q)
ok=false;
query[t]=query[st[t]];
t--;
}
for (j=0; j<=4*n; j++)
{
lazy[j]=-1;
}
for (j=1; j<=q; j++)
{
lazy_update(1,n,1,query[j].l+1,query[j].r+1,query[j].x);
}
for (j=1; j<=n; j++)
{
placed[j-1]=0;
val[j].nr=qry(1,n,1,j,j);
val[j].poz=j;
}
next=n-1;
nextsmall=0;
sort(val+1,val+1+n,cmp2);
for (j=1; j<=n; j++)
{
if (!placed[val[j].nr] && val[j].nr!=-1)
{
finl[val[j].poz]=val[j].nr;
placed[val[j].nr]=1;
}
else if (val[j].nr==-1)
{
while (placed[nextsmall] && nextsmall<=n-1)
{
nextsmall++;
}
finl[val[j].poz]=nextsmall;
placed[nextsmall]=1;
}
else
{
while (placed[next] && next>=0)
{
next--;
}
if (next<val[j].nr)
ok=false;
finl[val[j].poz]=next;
placed[next]=1;
}
}
if (ok==true)
{
for (j=1; j<=n; j++)
{
cout << finl[j] << " ";
}
}
else
{
for (j=1;j<=n;j++)
{
cout << "-1 ";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |