#include <bits/stdc++.h>
using namespace std;
const int nx=1e3+5;
int n, q, l, r, a, b[nx], dp[nx][nx], cnt, used[nx], res[nx];
vector<pair<int, int>> d[nx];
pair<int, int> merge(pair<int, int> x, pair<int, int> y)
{
if (x.first==-1||y.first==-1) return {-1, -1};
if (max(x.first, y.first)<=min(x.second, y.second)) return {max(x.first, y.first), min(x.second, y.second)};
return {-1, -1};
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>q;
for (int i=0; i<q; i++) cin>>l>>r>>a, d[a].push_back({l, r});
for (int i=n-1; i>=0; i--)
{
for (int j=0; j<n; j++) dp[i][j]=b[j];
pair<int, int> cur={0, n-1};
for (auto x:d[i])
{
cur=merge(cur, x);
for (int j=x.first; j<=x.second; j++) b[j]=1;
}
if (cur.first==-1)
{
for (int j=0; j<n; j++) cout<<-1<<' ';
cout<<'\n';
return 0;
}
for (int j=0; j<cur.first; j++) dp[i][j]=1;
for (int j=cur.second+1; j<n; j++) dp[i][j]=1;
}
for (int i=0; i<n; i++)
{
for (int j=0; j<n; j++)
{
if (!dp[i][j]&&!used[j])
{
cnt++;
used[j]=1;
res[j]=i;
break;
}
}
if (cnt!=i+1)
{
for (int j=0; j<n; j++) cout<<-1<<' ';
cout<<'\n';
return 0;
}
}
for (int i=0; i<n; i++) cout<<res[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... |