fork download
  1. /*
  2. Task: 356A
  3. Date: Dec 23, 2020
  4. Author: aLittleLove (Minh Vu)
  5. */
  6.  
  7. #include<bits/stdc++.h>
  8.  
  9. using namespace std;
  10. const int N = 3e5 + 5;
  11.  
  12. int n, m;
  13. int st[N<<2];
  14.  
  15. void down(int k)
  16. {
  17. if (st[k<<1]==0) st[k<<1] = st[k];
  18. if (st[k<<1|1]==0) st[k<<1|1] = st[k];
  19. st[k] = 0;
  20. }
  21.  
  22. void update(int k, int l, int r, int u, int v, int x)
  23. {
  24. if (r<u || l>v) return;
  25. if (l>=u && r<=v)
  26. {
  27. if (st[k]==0) st[k] = x;
  28. return;
  29. }
  30. down(k);
  31. int mid = (l + r) >> 1;
  32. update(k<<1,l,mid,u,v,x);
  33. update(k<<1|1,mid+1,r,u,v,x);
  34. }
  35.  
  36. void show(int k, int l, int r)
  37. {
  38. if (l==r)
  39. {
  40. cout << st[k] << " ";
  41. return;
  42. }
  43. down(k);
  44. int mid = (l + r) >> 1;
  45. show(k<<1,l,mid);
  46. show(k<<1|1,mid+1,r);
  47. }
  48.  
  49. void Solve()
  50. {
  51. cin >> n >> m;
  52. for (int i=1; i<=m; i++)
  53. {
  54. int u, v, x; cin >> u >> v >> x;
  55. update(1,1,n,u,x-1,x);
  56. update(1,1,n,x+1,v,x);
  57. }
  58. show(1,1,n);
  59. }
  60.  
  61. int main()
  62. {
  63. ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  64. //freopen("input.txt","r",stdin);
  65. int nTest;
  66. nTest = 1;
  67. while (nTest--) Solve();
  68.  
  69. return 0;
  70. }
Success #stdin #stdout 0s 5012KB
stdin
8 4
3 5 4
3 7 6
2 8 8
1 8 1
stdout
0 8 4 6 4 8 6 1