fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define all(v) v.begin(),v.end()
  4. #define MASK(i) (1LL << (i))
  5. #define ii pair<int,int>
  6. #define fi first
  7. #define se second
  8. #define endl '\n'
  9. #define forr(i,l,r,add) for(int i = l;i <= r; i = i + add)
  10. #define fodd(i,l,r,sub) for(int i = l;i >= r ; i = i - sub)
  11. template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
  12. template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
  13.  
  14. using namespace std;
  15.  
  16. mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
  17. #define rand rd
  18.  
  19. long long Rand(long long l , long long h){
  20. assert(l <= h);
  21. return l + 1ll * rd() % (h - l + 1) * (rd() % (h - l + 1)) % (h - l + 1);
  22. }
  23.  
  24.  
  25. //////////////////////////////////////////////////////////// end of template ////////////////////////////////////////////////////////////
  26.  
  27. const int MAX = 1e6 + 5;
  28. int SZ = 1e6 + 1;
  29. int num;
  30. #define ldb long double
  31.  
  32. int fenwick[2][MAX];
  33.  
  34. void update(int fen[] , int u , int val){
  35. while(u <= SZ){
  36. fen[u] += val;
  37. u += u & -u;
  38. }
  39. }
  40.  
  41. int GET(int fen[] , int u){
  42. int sum = 0;
  43. while(u) sum = sum + fen[u] , u -= u & -u;
  44. return sum;
  45. }
  46.  
  47. int calc(int ok , int l , int r){
  48. return GET(fenwick[ok] , r) - GET(fenwick[ok] , l - 1);
  49. }
  50.  
  51. void INP(){
  52. cin >> num;
  53. while(num--){
  54. int dk;
  55. cin >> dk;
  56. if(dk == 1){
  57. int x , val;
  58. cin >> x >> val;
  59. x++;
  60. update(fenwick[0] , x , val);
  61. }
  62. else if(dk == 2){
  63. int x , val;
  64. cin >> x >> val;
  65. x++;
  66. update(fenwick[1] , x , val);
  67. }
  68. else {
  69. int a , b , x , y;
  70. cin >> a >> b >> x >> y;
  71. if(a > x) swap(a , x);
  72. if(b > y) swap(b , y);
  73. a++ , b++ , x++ , y++;
  74. ldb res = 0;
  75. int d = abs(a - x);
  76. if(a == x){
  77. int tmp = calc(0 , a , a);
  78. res += (ldb) tmp / max(1 , d);
  79. }
  80. else {
  81. int tmp = calc(0 , a , x - 1);
  82. res += (ldb) tmp / max(1 , d);
  83. }
  84. d = abs(b - y);
  85. if(b == y){
  86. int tmp = calc(1 , y , y);
  87. res += (ldb) tmp / max(1 , d);
  88. }
  89. else {
  90. int tmp = calc(1 , b , y - 1);
  91. res += (ldb) tmp / max(1 , d);
  92. }
  93.  
  94. cout << setprecision(10) << fixed << res << endl;
  95. }
  96. }
  97. }
  98.  
  99. int main()
  100. {
  101. ios_base::sync_with_stdio(false);
  102. cin.tie(0);
  103. cout.tie(0);
  104. #define TASK ""
  105. //freopen(TASK".inp" , "r" , stdin);
  106. //freopen(TASK".out" , "w" , stdout);
  107. INP();
  108. return 0;
  109. }
  110.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty