Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define endl "\n"
- using namespace std;
- using ll = long long;
- using pii = pair<int, int>;
- constexpr int N = 1e5+1;
- constexpr ll INF = (1LL<<32)+7;
- struct Que
- {
- ll l,r,v;
- };
- ll n, ln, nq, tr[4*N], arr[N];
- Que q[N];
- bool f = true;
- void build(ll id = 0, ll l = 0, ll r = n)
- {
- if (l==r)
- return;
- if (l+1==r)
- {
- tr[id]=-INF;
- return;
- }
- ll mid = (r+l)>>1;
- build((id<<1)+1, l, mid);
- build((id<<1)+2, mid, r);
- tr[id]=-INF;
- }
- void build_2(ll id = 0, ll l = 0, ll r = n)
- {
- if (l==r)
- return;
- if (l+1==r)
- {
- tr[id]=arr[l];
- return;
- }
- ll mid = (r+l)>>1;
- build_2((id<<1)+1, l, mid);
- build_2((id<<1)+2, mid, r);
- tr[id]=min(tr[(id<<1)+1], tr[(id<<1)+2]);
- }
- void upd(ll val, ll l, ll r, ll id = 0, ll cl = 0, ll cr = n)
- {
- if (l>cr||r<cl||l==r||val<=tr[id])
- return;
- if (cl==l&&cr==r)
- {
- tr[id]=max(tr[id], val);
- return;
- }
- ll mid = (cl+cr)>>1;
- upd(val, max(l, cl), min(r, mid), (id<<1)+1, cl, mid);
- upd(val, max(l, mid), min(r, cr), (id<<1)+2, mid, cr);
- return;
- }
- void update(Que q)
- {
- upd(q.v, q.l-1, q.r);
- }
- ll get_el(ll i, ll id = 0, ll cl = 0, ll cr = n)
- {
- if (cl+1==cr)
- return tr[id];
- ll mid = (cl+cr)>>1;
- return max(tr[id],
- (i<mid?get_el(i, (id<<1)+1, cl, mid):
- get_el(i, (id<<1)+2, mid, cr)));
- }
- ll get(ll l, ll r, ll id = 0, ll cl = 0, ll cr = n)
- {
- if (l>cr||r<cl||l==r)
- return INF;
- if(l==cl&&r==cr)
- return tr[id];
- ll mid = (cl+cr)>>1;
- return min(get(max(l, cl), min(r, mid), (id<<1)+1, cl, mid),
- get(max(l, mid), min(r, cr), (id<<1)+2, mid, cr));
- }
- ll get_ans(Que q)
- {
- return get(q.l-1, q.r);
- }
- ll close(ll n)
- {
- ll res = 1;
- while(res<n)
- {
- res<<=1;
- }
- return res;
- }
- void Solve()
- {
- cin >> n >> nq;
- ln = n;
- n=close(n);
- build();
- for (ll i = 0; i < nq; i++)
- {
- cin >> q[i].l >> q[i].r >> q[i].v;
- update(q[i]);
- }
- for (ll i = 0; i < ln; i++)
- {
- arr[i]=get_el(i)==-INF?(1LL<<31)-1:get_el(i);
- }
- build_2();
- for (ll i = 0; i < nq; i++)
- {
- if (get_ans(q[i])!=q[i].v)
- f = false;
- }
- if (!f)
- {
- cout << "inconsistent";
- return;
- }
- cout << "consistent"<< endl;
- for (ll i = 0; i < ln; i++)
- {
- cout << arr[i] << " ";
- }
- }
- int main()
- {
- freopen("rmq.in", "r", stdin);
- freopen("rmq.out", "w", stdout);
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- Solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement