fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define OPEN(PATH) freopen(PATH".INP", "r", stdin); freopen(PATH".OUT", "w", stdout);
  5. #define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
  6. #define FOD(i, a, b) for (int i = (a); i >= (b); --i)
  7. #define REP(i, n) for (int i = 0; i < (n); ++i)
  8. #define MASK(n) (1LL << (n))
  9. #define BIT(i, n) (((n) >> (i)) & 1)
  10. #define pb push_back
  11. #define fi first
  12. #define se second
  13. #define ll long long
  14. #define db double
  15. #define ull unsigned ll
  16. #define pii pair<int, int>
  17. #define pll pair<ll, ll>
  18. #define pli pair<ll, int>
  19. #define pil pair<int, ll>
  20. #define all(x) x.begin(), x.end()
  21. #define sz(s) (int)s.size()
  22. #define el cout << '\n'
  23. #define elif else if
  24.  
  25. template <class GAU, class VN>
  26. bool maximize(GAU &x, const VN &y)
  27. {
  28. if (x < y)
  29. {
  30. x = y;
  31. return true;
  32. }
  33. else return false;
  34. }
  35.  
  36. template <class GAU, class VN>
  37. bool minimize(GAU &x, const VN &y)
  38. {
  39. if (x > y)
  40. {
  41. x = y;
  42. return true;
  43. }
  44. else return false;
  45. }
  46.  
  47. const int N = 1e6;
  48. int q;
  49. ll bit1[N + 7], bit2[N + 7];
  50.  
  51. void update(ll bit[], int idx, ll val)
  52. {
  53. for (; idx <= N; idx += idx & -idx) bit[idx] += val;
  54. }
  55. ll get(ll bit[], int idx)
  56. {
  57. ll ret = 0;
  58. for (; idx > 0; idx -= idx & -idx) ret += bit[idx];
  59. return ret;
  60. }
  61.  
  62. void solve()
  63. {
  64. int type;
  65. while (q--)
  66. {
  67. cin >> type;
  68. if (type == 1)
  69. {
  70. int x; ll v; cin >> x >> v;
  71. update(bit1, x + 1, v);
  72. }
  73. elif (type == 2)
  74. {
  75. int y; ll v; cin >> y >> v;
  76. update(bit2, y + 1, v);
  77. }
  78. else
  79. {
  80. int x, y, u, v; cin >> x >> y >> u >> v;
  81. if (x > u) swap(x, u);
  82. if (y > v) swap(y, v);
  83. ll disU = u - x, disV = v - y;
  84. db res = 0.0;
  85. if (disU)
  86. res += (db)(get(bit1, u) - get(bit1, x)) / disU;
  87. else
  88. res += (db)(get(bit1, x + 1) - get(bit1, x));
  89.  
  90. if (disV)
  91. res += (db)(get(bit2, v) - get(bit2, y)) / disV;
  92. else
  93. res += (db)(get(bit2, y + 1) - get(bit2, y));
  94. cout << fixed << setprecision(8) << res, el;
  95. }
  96. }
  97. }
  98.  
  99. void process()
  100. {
  101. cin >> q;
  102. solve();
  103. }
  104.  
  105. signed main()
  106. {
  107. ios::sync_with_stdio(0);
  108. cin.tie(0);
  109. cout.tie(0);
  110. process();
  111. return 0;
  112. }
  113.  
  114.  
  115.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty