Submission #891408

#TimeUsernameProblemLanguageResultExecution timeMemory
891408stefanneaguRMQ (NOI17_rmq)C++17
100 / 100
104 ms13480 KiB
#include <bits/stdc++.h> using namespace std; const int nmax = 1e5 + 1; struct str { int a, b, val; const bool operator < (str ult) const { return val < ult.val; } } v[nmax]; int aint[4 * nmax], lz[4 * nmax], fp[nmax], lp[nmax], fin[nmax]; vector<vector<int>> place; void lazy(int nod, int st, int dr) { aint[nod] = lz[nod]; if(st != dr) { lz[nod << 1] = lz[nod]; lz[nod << 1|1] = lz[nod]; } lz[nod] = 0; } void update(int nod, int st, int dr, int l, int r, int val) { if(lz[nod]) { lazy(nod, st, dr); } if(st > r || dr < l) { return; } if(l <= st && dr <= r) { lz[nod] = val; lazy(nod, st, dr); return; } int mid = (st + dr) / 2; update(nod << 1, st, mid, l, r, val); update(nod << 1|1, mid + 1, dr, l, r, val); } int query(int nod, int st, int dr, int poz) { if(lz[nod]) { lazy(nod, st, dr); } if(st == dr) { return aint[nod]; } int mid = (st + dr) / 2; if(poz <= mid) { return query(nod << 1, st, mid, poz); } else { return query(nod << 1|1, mid + 1, dr, poz); } } int main() { int n, q; cin >> n >> q; for(int i = 0; i <= n; i ++) { fp[i] = 1, lp[i] = n; } for(int i = 1; i <= q; i ++) { int a, b, val; cin >> a >> b >> val; a ++; b ++; v[i].a = a, v[i].b = b, v[i].val = val; fp[val] = max(fp[val], a); lp[val] = min(lp[val], b); } sort(v + 1, v + q + 1); for(int i = 1; i <= q; i ++) { update(1, 1, n, v[i].a, v[i].b, v[i].val); } place.resize(n + 1); for(int i = 1; i <= n; i ++) { int x = query(1, 1, n, i); place[x].push_back(i); } set<int> curr; for(int i = 0; i < n; i ++) { for(auto it : place[i]) { curr.insert(it); } auto poz = curr.lower_bound(fp[i]); if(poz == curr.end() || (*poz) > lp[i]) { for(int x = 1; x <= n; x ++) { cout << "-1 "; } return 0; } fin[(*poz)] = i; curr.erase(poz); } for(int i = 1; i <= n; i ++) { cout << fin[i] << " "; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...