Advertisement
limimage

task C

May 18th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define endl "\n"
  3.  
  4. using namespace std;
  5. using ll = long long;
  6. using pii = pair<int, int>;
  7.  
  8. constexpr int N = 1e5+1;
  9. constexpr ll INF = (1LL<<32)+7;
  10.  
  11. struct Que
  12. {
  13. ll l,r,v;
  14. };
  15.  
  16. ll n, ln, nq, tr[4*N], arr[N];
  17. Que q[N];
  18. bool f = true;
  19.  
  20. void build(ll id = 0, ll l = 0, ll r = n)
  21. {
  22. if (l==r)
  23. return;
  24. if (l+1==r)
  25. {
  26. tr[id]=-INF;
  27. return;
  28. }
  29. ll mid = (r+l)>>1;
  30. build((id<<1)+1, l, mid);
  31. build((id<<1)+2, mid, r);
  32. tr[id]=-INF;
  33. }
  34.  
  35. void build_2(ll id = 0, ll l = 0, ll r = n)
  36. {
  37. if (l==r)
  38. return;
  39. if (l+1==r)
  40. {
  41. tr[id]=arr[l];
  42. return;
  43. }
  44. ll mid = (r+l)>>1;
  45. build_2((id<<1)+1, l, mid);
  46. build_2((id<<1)+2, mid, r);
  47. tr[id]=min(tr[(id<<1)+1], tr[(id<<1)+2]);
  48. }
  49.  
  50.  
  51. void upd(ll val, ll l, ll r, ll id = 0, ll cl = 0, ll cr = n)
  52. {
  53. if (l>cr||r<cl||l==r||val<=tr[id])
  54. return;
  55. if (cl==l&&cr==r)
  56. {
  57. tr[id]=max(tr[id], val);
  58. return;
  59. }
  60. ll mid = (cl+cr)>>1;
  61. upd(val, max(l, cl), min(r, mid), (id<<1)+1, cl, mid);
  62. upd(val, max(l, mid), min(r, cr), (id<<1)+2, mid, cr);
  63. return;
  64. }
  65.  
  66. void update(Que q)
  67. {
  68. upd(q.v, q.l-1, q.r);
  69. }
  70.  
  71. ll get_el(ll i, ll id = 0, ll cl = 0, ll cr = n)
  72. {
  73. if (cl+1==cr)
  74. return tr[id];
  75. ll mid = (cl+cr)>>1;
  76. return max(tr[id],
  77. (i<mid?get_el(i, (id<<1)+1, cl, mid):
  78. get_el(i, (id<<1)+2, mid, cr)));
  79. }
  80.  
  81. ll get(ll l, ll r, ll id = 0, ll cl = 0, ll cr = n)
  82. {
  83. if (l>cr||r<cl||l==r)
  84. return INF;
  85. if(l==cl&&r==cr)
  86. return tr[id];
  87. ll mid = (cl+cr)>>1;
  88. return min(get(max(l, cl), min(r, mid), (id<<1)+1, cl, mid),
  89. get(max(l, mid), min(r, cr), (id<<1)+2, mid, cr));
  90. }
  91.  
  92. ll get_ans(Que q)
  93. {
  94. return get(q.l-1, q.r);
  95. }
  96.  
  97. ll close(ll n)
  98. {
  99. ll res = 1;
  100. while(res<n)
  101. {
  102. res<<=1;
  103. }
  104. return res;
  105. }
  106.  
  107. void Solve()
  108. {
  109. cin >> n >> nq;
  110. ln = n;
  111. n=close(n);
  112. build();
  113. for (ll i = 0; i < nq; i++)
  114. {
  115. cin >> q[i].l >> q[i].r >> q[i].v;
  116. update(q[i]);
  117. }
  118. for (ll i = 0; i < ln; i++)
  119. {
  120. arr[i]=get_el(i)==-INF?(1LL<<31)-1:get_el(i);
  121. }
  122. build_2();
  123. for (ll i = 0; i < nq; i++)
  124. {
  125. if (get_ans(q[i])!=q[i].v)
  126. f = false;
  127. }
  128. if (!f)
  129. {
  130. cout << "inconsistent";
  131. return;
  132. }
  133. cout << "consistent"<< endl;
  134. for (ll i = 0; i < ln; i++)
  135. {
  136. cout << arr[i] << " ";
  137. }
  138. }
  139.  
  140. int main()
  141. {
  142. freopen("rmq.in", "r", stdin);
  143. freopen("rmq.out", "w", stdout);
  144. ios_base::sync_with_stdio(false);
  145. cin.tie(nullptr);
  146. cout.tie(nullptr);
  147. Solve();
  148. return 0;
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement