Submission #1162735

#TimeUsernameProblemLanguageResultExecution timeMemory
1162735DangKhoizzzzRMQ (NOI17_rmq)C++20
0 / 100
1096 ms2632 KiB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pii pair <int , int>
#define arr3 array <int , 3>

/*
+ array limit ???
+ special case ??? n = 1?
+ time limit ???
*/

using namespace std;

const int INF = 1e9 + 7;
const int maxn = 1e5 + 7;

int n , q , mark[maxn] , ans[maxn];
arr3 query[maxn];
vector <pii> num[maxn];

bool check = 1;

void solve()
{
    cin >> n >> q;
    for(int i = 1; i <= q; i++)
    {
        cin >> query[i][0] >> query[i][1] >> query[i][2];
        query[i][0]++; query[i][1]++; query[i][2]++;
        num[query[i][2]].push_back({query[i][0] , query[i][1]});
    }
    set <int> uu , index; // unused
    for(int i = 1; i <= n; i++)
    {
        uu.insert(i); index.insert(i);
    }

    index.insert(n+1);

    vector <int> val;

    for(int i = n; i >= 1; i--)
    {
        if(num[i].empty()) continue;

        int limL = 0 , limR = n+1;

        set <int> pos;

        while(!uu.empty() && *uu.rbegin() >= i)
        {
            val.push_back(*uu.rbegin());
            uu.erase(*uu.rbegin());
        }

        for(pii tmp: num[i])
        {
            int cur = *index.lower_bound(tmp.fi);
            limL = max(limL , tmp.fi);
            limR = min(limR , tmp.se);
            while(cur <= tmp.se)
            {
                pos.insert(cur);
                mark[cur] = i;
                index.erase(cur);
                cur = *index.upper_bound(cur);
            }
        }

        if(limL > limR || *pos.lower_bound(limL) > limR || pos.size() > val.size())
        {
            check = false; break;
        }

        ans[*pos.lower_bound(limL)] = i;
        pos.erase(pos.lower_bound(limL));
        val.pop_back();

        for(int p: pos)
        {
            ans[p] = val.back();
            val.pop_back();
        }
    }

    if(!check)
    {
        for(int i = 1; i <= n; i++) cout << -1 << ' ';
        return;
    }
    for(int i = 1; i <= n; i++) cout << --ans[i] << ' ';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...