DSA
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.2 KiB

  1. /*
  2. #pragma GCC target ("avx2")
  3. #pragma GCC optimize ("Ofast")
  4. #pragma GCC optimize ("unroll-loops")
  5. */
  6. #include "bits/stdc++.h"
  7. #define iosb ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
  8. #define BIT(x) __builtin_popcount(x)
  9. #define all(x) x.begin() , x.end()
  10. #define F first
  11. #define S second
  12. #define pb push_back
  13. using namespace std ;
  14. typedef unsigned long long UL ;
  15. typedef long long L ;
  16. typedef string T ;
  17. typedef int I ;
  18. const I MaxN = 8e6+123 ;
  19. const I MOD = 1e9+7 ;
  20. const I inf = 2e9+7 ;
  21. const L INF = 2e18+7 ;
  22. struct item{
  23. int cnt = 0, pref = 0, suff = 0, sum = 0 ;
  24. } t[MaxN] ;
  25. int m[MaxN] ;
  26. void push(int v, int x, int y)
  27. {
  28. if (m[v] != -1 && v*2+1 < 4000004)
  29. {
  30. m[v*2] = m[v*2+1] = m[v] ;
  31. m[v] = -1 ;
  32. int z = (x+y)/2 ;
  33. t[v*2].sum = (z*1ll-x*1ll+1ll) * (m[v*2]*1ll) ;
  34. t[v*2].pref = m[v*2] ;
  35. t[v*2].cnt = m[v*2] ;
  36. t[v*2].suff = m[v*2] ;
  37. t[v*2+1].sum = (y*1ll-z*1ll) * (m[v*2+1]*1ll) ;
  38. t[v*2+1].pref = m[v*2+1] ;
  39. t[v*2+1].cnt = m[v*2+1] ;
  40. t[v*2+1].suff = m[v*2+1] ;
  41. }
  42. }
  43. void update(int l, int r, int c, int v, int x, int y)
  44. {
  45. if (l <= x && y <= r) {
  46. t[v].sum = c*1ll * (y*1ll-x*1ll+1ll) ;
  47. t[v].cnt = c ;
  48. t[v].pref = c ;
  49. t[v].suff = c ;
  50. m[v] = c ;
  51. return ;
  52. }
  53. if (y < l || r < x)
  54. return ;
  55. push(v, x, y) ;
  56. int z = (x+y)/2 ;
  57. update(l, r, c, v * 2, x, z) ;
  58. update(l, r, c, v * 2 + 1, z+1, y) ;
  59. t[v].pref = t[v*2].pref,
  60. t[v].suff = t[v*2+1].suff,
  61. t[v].sum = t[v*2].sum + t[v*2+1].sum,
  62. t[v].cnt = t[v*2].cnt + t[v*2+1].cnt - (t[v*2].suff && t[v*2+1].pref?1:0);
  63. }
  64. int main()
  65. {
  66. freopen("painter.in", "r", stdin) ;
  67. freopen("painter.out", "w", stdout) ;
  68. for(int i = 0 ; i < MaxN ; ++i)
  69. m[i] = -1 ;
  70. int n ;
  71. cin >> n ;
  72. while(n--)
  73. {
  74. char c ;
  75. int l, r ;
  76. cin >> c >> l >> r ;
  77. if(c == 'W') c = 0 ;
  78. else c = 1 ;
  79. update(l+500001, l+r-1+500001, int(c), 1, 1, 2000000);
  80. cout << t[1].cnt << ' ' << t[1].sum << '\n' ;
  81. }
  82. }
  83. /*
  84. 7
  85. W 2 3
  86. B 2 2
  87. B 4 2
  88. B 3 2
  89. B 7 2
  90. W 3 1
  91. W 0 10
  92. */