Submission #891291

#TimeUsernameProblemLanguageResultExecution timeMemory
891291IrateRMQ (NOI17_rmq)C++14
23 / 100
1056 ms432 KiB
#include<bits/stdc++.h> using namespace std; struct Query{ int l, r, val; bool operator<(Query &other){ return val < other.val; } }; struct SegmentTree{ vector<int>sTree; SegmentTree(int n){ sTree.resize(4 * n); } void Build(int node, int l, int r, vector<int>&v){ if(l == r){ sTree[node] = v[l - 1]; } else{ int mid = (l + r) >> 1; Build(node * 2, l, mid, v); Build(node * 2 + 1, mid + 1, r, v); sTree[node] = min(sTree[node * 2], sTree[node * 2 + 1]); } } int Query(int node, int l, int r, int ql, int qr){ if(ql <= l && r <= qr){ return sTree[node]; } if(ql > r || l > qr)return 1e9; int mid = (l + r) >> 1; int lc = Query(node * 2, l, mid, ql, qr); int rc = Query(node * 2 + 1, mid + 1, r, ql, qr); return min(lc, rc); } }; struct LazySegmentTree{ vector<int>sTree; vector<int>lazy; LazySegmentTree(int n){ sTree.assign(4 * n, -1); lazy.assign(4 * n, -1); } void Propagate(int node, int l, int r){ if(lazy[node] == -1)return; if(l != r){ lazy[node * 2] = lazy[node * 2 + 1] = lazy[node]; } else { sTree[node] = lazy[node]; } lazy[node] = -1; } void R_Update(int node, int l, int r, int ql, int qr, int val){ Propagate(node, l, r); if(ql <= l && r <= qr){ lazy[node] = val; Propagate(node, l, r); return; } if(ql > r || l > qr)return; int mid = (l + r) >> 1; R_Update(node * 2, l, mid, ql, qr, val); R_Update(node * 2 + 1, mid + 1, r, ql, qr, val); } int Get(int node, int l, int r, int pos){ Propagate(node, l, r); if(l == r){ return sTree[node]; } else{ int mid = (l + r) >> 1; if(pos <= mid){ return Get(node * 2, l, mid, pos); } else{ return Get(node * 2 + 1, mid + 1, r, pos); } } } }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, q; cin >> n >> q; vector<Query>queries(q); for(int i = 0;i < q;++i){ int l, r, val; cin >> l >> r >> val; queries[i] = {l, r, val}; } sort(queries.begin(), queries.end()); // set<int>s; // for(int i = 0;i < n;++i)s.insert(i); // vector<int>v(n, -1); // vector<bool>chosen(n); // for(int i = 0;i < q;++i){ // int l = queries[i].l, r = queries[i].r, val = queries[i].val; // s.erase(val); // for(int j = l;j <= r;++j){ // v[j] = val; // } // } // bool f = false; // for(int i = 0;i < n;++i){ // if(v[i] != -1 && !chosen[v[i]])chosen[v[i]] = 1; // else { // auto itr = s.upper_bound(v[i]); // if(itr == s.end()){ // for(int j = 0;j < n;++j){ // cout << -1 << " "; // } // f = true; // return 0; // } // v[i] = *itr; // chosen[*itr] = 1; // s.erase(s.find(*itr)); // } // } // if(!f){ // SegmentTree tree1(n); // tree1.Build(1, 1, n, v); // bool check = true; // for(int i = 0;i < q && check;++i){ // int l = queries[i].l, r = queries[i].r, val = queries[i].val; // if(tree1.Query(1, 1, n, l + 1, r + 1) != val){ // check = 0; // } // } // if(check){ // for(int i = 0;i < n;++i){ // cout << v[i] << " "; // } // } // else{ // for(int i = 0;i < n;++i){ // cout << -1 << " "; // } // } // cout << '\n'; // } vector<int>tempo(n); for(int i = 0;i < n;++i)tempo[i] = i; do{ SegmentTree tree1(n); tree1.Build(1, 1, n, tempo); bool check = true; for(int i = 0;i < q && check;++i){ int l = queries[i].l, r = queries[i].r, val = queries[i].val; if(tree1.Query(1, 1, n, l + 1, r + 1) != val){ check = 0; } } if(check){ for(int &i : tempo)cout << i << " "; return 0; } }while(next_permutation(tempo.begin(), tempo.end())); for(int i = 0;i < n;++i){ cout << -1 << " "; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...