当前位置:   article > 正文

Educational Codeforces Round 46 (Rated for Div. 2) C - Covered Points Count_you are given n n segments on a coordinate line; e

you are given n n segments on a coordinate line; each endpoint of every segm
C. Covered Points Count
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given nn segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.

Your task is the following: for every k[1..n]k∈[1..n], calculate the number of points with integer coordinates such that the number of segments that cover these points equals kk. A segment with endpoints lili and riri covers point xx if and only if lixrili≤x≤ri.

Input

The first line of the input contains one integer nn (1n21051≤n≤2⋅105) — the number of segments.

The next nn lines contain segments. The ii-th line contains a pair of integers li,rili,ri (0liri10180≤li≤ri≤1018) — the endpoints of the ii-th segment.

Output

Print nn space separated integers cnt1,cnt2,,cntncnt1,cnt2,…,cntn, where cnticnti is equal to the number of points such that the number of segments that cover these points equals to ii.

Examples
input
Copy
3
0 3
1 3
3 8
output
Copy
6 2 1 
input
Copy
3
1 3
2 4
5 7
output
Copy
5 2 0 
Note

The picture describing the first example:

Points with coordinates [0,4,5,6,7,8][0,4,5,6,7,8] are covered by one segment, points [1,2][1,2] are covered by two segments and point [3][3] is covered by three segments.

The picture describing the second example:

Points [1,4,5,6,7][1,4,5,6,7] are covered by one segment, points [2,3][2,3] are covered by two segments and there are no points covered by three segments.

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int MAXN = 200000 + 10;
  4. struct f
  5. {
  6. long long head;
  7. int shu;
  8. }a[2 * MAXN];
  9. long long mark[MAXN];
  10. int com(const f &u , const f &v)
  11. {
  12. if(u.head == v.head)
  13. return u.shu > v.shu;
  14. return u.head < v.head;
  15. }
  16. int main()
  17. {
  18. int n;
  19. cin >> n;
  20. int num = 0;
  21. for(int i = 1; i <= n * 2; i ++)
  22. {
  23. cin >> a[i].head;
  24. if(i & 1)
  25. a[i].shu = 1;
  26. else
  27. a[i].shu = 0;
  28. }
  29. //a[n + 1].head = a[n + 1].tail = 1e18 + 1;
  30. //cout << endl;
  31. sort( a + 1, a + 2 * n + 1, com);
  32. //for(int i = 1 ; i <= 2 * n ; i ++)
  33. // cout << a[i].head << " " << a[i].shu << endl;
  34. //cout << endl;
  35. int temp ;
  36. long long f = 0;
  37. for(int i = 1 ; i <= n * 2; i ++)
  38. {
  39. //mark[num] += a[i].head - a[i - 1].head;
  40. if(a[i].shu == 1)
  41. {
  42. if(a[i].head - f - 1 >=0)
  43. mark[num] += a[i].head - f - 1;
  44. f = a[i].head;
  45. temp = i;
  46. int t = num;
  47. //cout << "!" << " " << t << endl;
  48. while(a[temp].head == a[temp + 1].head && temp + 1 <= n * 2)
  49. {
  50. //cout << a[temp + 1].shu << endl;
  51. //t ++;
  52. if(a[temp + 1].shu > 0)
  53. {
  54. num ++;
  55. t ++;
  56. //cout << "!" << endl;
  57. }
  58. //num ++;
  59. else
  60. num --;
  61. temp ++;
  62. }
  63. //cout << t << endl;
  64. num ++;
  65. t ++;
  66. //cout << num << " " << t << endl;
  67. mark[t] ++;
  68. i += (temp - i);
  69. //for(int j = 1; j <= 3 ; j ++)
  70. // cout << mark[j] << " ";
  71. //cout << endl;
  72. }
  73. else
  74. {
  75. if(a[i].head - f - 1 >= 0)
  76. mark[num] += a[i].head - f - 1;
  77. f = a[i].head;
  78. int t = num ;
  79. temp = i;
  80. while(a[temp].head == a[temp + 1].head && temp + 1 <= n * 2)
  81. {
  82. if(a[temp + 1].shu > 0)
  83. {
  84. num ++;
  85. t ++;
  86. }
  87. // num ++;
  88. else
  89. num --;
  90. temp ++;
  91. }
  92. //cout << num << " " << t << endl;
  93. mark[t] ++ ;
  94. num --;
  95. //for(int j = 1 ; j <= 3; j ++)
  96. // cout << mark[j] << " ";
  97. //cout << endl;
  98. i += (temp - i) ;
  99. }
  100. }
  101. cout << mark[1];
  102. for(int i = 2; i <= n ; i ++)
  103. cout << " " << mark[i];
  104. return 0;
  105. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/912648
推荐阅读
相关标签
  

闽ICP备14008679号