Advertisement
rjlth

Untitled

Jan 3rd, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. #include <math.h>
  2. #include <stdio.h>
  3. #include <utility>
  4. #include <stdlib.h>
  5. #include <iostream>
  6. #include <algorithm>
  7. #define For(i,a,b) for((i)=(a);(i)<=(b);(i)++)
  8. #define Fod(i,a,b) for((i)=(a);(i)>=(b);(i)--)
  9. #define sz(x) int((x).size())
  10. #define NON -(1ll<<35)
  11. #define mp make_pair
  12. using namespace std;
  13. pair<pair<int,int>,int> q[100005];
  14. bool F[280005];
  15. long long t[280005],a[100005],Mn;
  16. int l,r,x,n,m,i,j,tsz;
  17. int lev,prav,zam;
  18. void push(int v,int L,int R)
  19. {
  20. if(F[v])
  21. {
  22. if(L<R)
  23. {
  24. F[v*2]=F[v*2+1]=1;
  25. t[v*2]=t[v*2+1]=t[v];
  26. }
  27. F[v]=0;
  28. }
  29. }
  30.  
  31. void upd(int v,int L,int R)
  32. {
  33. push(v,L,R);
  34. if(R<l || L>r) return;
  35. if(l<=L && R<=r)
  36. {
  37. if(x<t[v])
  38. {
  39. puts("inconsistent");
  40. exit(0);
  41. }
  42. F[v]=1; t[v]=x;
  43. push(v,L,R);
  44. return;
  45. }
  46. upd(v*2,L,(L+R)/2); upd(v*2+1,(L+R)/2+1,R);
  47. if(t[v*2]==NON) t[v]=t[v*2+1];
  48. else if(t[v*2+1]==NON) t[v]=t[v*2];
  49. else t[v]=min(t[v*2],t[v*2+1]);
  50. }
  51.  
  52. void Min(int v,int L,int R)
  53. {
  54. push(v,L,R);
  55. if(R<l || L>r) return;
  56. if(l<=L && R<=r)
  57. {
  58. Mn=min(Mn,t[v]);
  59. return;
  60. }
  61. Min(v*2,L,(L+R)/2); Min(v*2+1,(L+R)/2+1,R);
  62. if(t[v*2]==NON) t[v]=t[v*2+1];
  63. else if(t[v*2+1]==NON) t[v]=t[v*2];
  64. else t[v]=min(t[v*2],t[v*2+1]);
  65. }
  66.  
  67. void out(int v,int L,int R)
  68. {
  69. if(t[v]==NON) return;
  70. if(F[v] || L==R)
  71. {
  72. For(i,L,R) a[i]=t[v];
  73. return;
  74. }
  75. out(v*2,L,(L+R)/2); out(v*2+1,(L+R)/2+1,R);
  76. }
  77. #define Left first.first
  78. #define Right first.second
  79. #define Num second
  80.  
  81. bool cmp(pair<pair<int,int>,int> X,pair<pair<int,int>,int> Y)
  82. {
  83. return (X.Num<Y.Num);
  84. }
  85.  
  86. int main()
  87. {
  88. freopen("rmq.in","r",stdin);
  89. freopen("rmq.out","w",stdout);
  90.  
  91. scanf("%d%d",&n,&m);
  92. for(tsz=1;tsz<n;tsz*=2);
  93. For(i,1,tsz*2-1) t[i]=NON;
  94.  
  95. For(i,1,m)
  96. {
  97. scanf("%d%d%d",&lev,&prav,&zam);
  98. q[i]=mp(mp(lev,prav),zam);
  99. }
  100.  
  101. sort(q+1,q+m+1,cmp);
  102. For(i,1,m)
  103. {
  104. l=q[i].Left; r=q[i].Right; x=q[i].Num;
  105. upd(1,1,tsz);
  106. }
  107.  
  108. out(1,1,tsz);
  109.  
  110. For(i,1,m)
  111. {
  112. l=q[i].Left; r=q[i].Right; x=q[i].Num;
  113. Mn=(1ll<<35); Min(1,1,tsz);
  114. if(x!=Mn) {
  115. printf("inconsistent");
  116. return 0;
  117. }
  118. }
  119.  
  120. puts("consistent");
  121.  
  122.  
  123. For(i,1,n) printf("%I64d ",a[i]);
  124.  
  125. return 0;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement