This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
#define ii pair<ll,ll>
#define iii pair<ll,ii>
#define fi first
#define se second
#define oo 1e18
#define bit(x,i) (((x)>>(i))&1)
using namespace std;
const int MOD = 1e9 + 7;
const int N = 5e3 + 5;
int n,q,l,r,a,c[N],ans[N],L[N],R[N];
bool vs[N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n>>q;
fo(i,0,n-1)
L[i] = 0,R[i] = n+1;
while(q--)
{
cin>>l>>r>>a;
fo(j,l,r)
c[j] = max(c[j], a);
L[a] = max(L[a], l);
R[a] = min(R[a], r);
}
fo(i,0,n-1)
vs[i] = 0,ans[i] = -1;
// fo(i,0,n-1)
// cout<<c[i]<<' ';
// cout<<'\n';
fo(j,0,n-1)
{
fo(i,L[j],R[j])
{
if(j >= c[i] && !vs[i])
{
ans[i] = j;
vs[i] = 1;
break;
}
}
}
fo(i,0,n-1)
if(ans[i] == -1)
{
fo(j,1,n)
cout<<-1<<' ';
return 0;
}
fo(i,0,n-1)
cout<<ans[i]<<' ';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |