fork download
  1. /*
  2. ** jan25
  3. */
  4. #include <iostream>
  5. #include <cstdio>
  6. #include <cstring>
  7. #include <vector>
  8.  
  9. int N = 300005;
  10.  
  11. using namespace std;
  12.  
  13. int next[300005];
  14. int ans[300005];
  15.  
  16. int getn(int i) {
  17. if (next[i] == i) return i;
  18. else return (next[i] = getn(next[i]));
  19. }
  20.  
  21. int main() {
  22. int n, m; cin>> n >> m;
  23.  
  24.  
  25. int a, b, i, j, k;
  26. i = 1;
  27. while (i <= n) next[i] = i++;
  28.  
  29. while (m--) {
  30. scanf("%d%d%d", &i, &j, &k);
  31.  
  32. while (i <= j) {
  33. i = getn(i);
  34. if (i != k) ans[i] = k;
  35. if (i < k) next[i] = k;
  36. else if (i > k) next[i] = j+1;
  37. ++i;
  38. }
  39. }
  40.  
  41. i = 1;
  42. while (i <= n) {
  43. if (ans[i] != i) printf("%d ", ans[i]);
  44. else printf("0 ");
  45. ++i;
  46. }
  47.  
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0s 5488KB
stdin
8 4
3 5 4
3 7 6
2 8 8
1 8 1
stdout
0 8 4 6 4 8 6 1