Advertisement
a53

dulciuri

a53
Sep 21st, 2022
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. const int nmax = 1e6;
  5.  
  6. ll cs[nmax+5], rs[nmax+5];
  7.  
  8. struct AIB {
  9. inline int lsb(int x) {
  10. return x & (-x);
  11. }
  12.  
  13. vector<ll> v;
  14. int len = 0;
  15. AIB(int n) {
  16. v.resize(n+1, 0);
  17. len = n;
  18. }
  19. void update(int pos, ll val) {
  20. for(int i=pos; i<=len; i+=lsb(i))
  21. v[i] += val;
  22. }
  23. ll query(int pos) {
  24. ll temp = 0;
  25. for(int i=pos; i>=1; i-=lsb(i))
  26. temp += v[i];
  27. return temp;
  28. }
  29. };
  30.  
  31. int main() {
  32. ifstream f("dulciuri.in");
  33. ofstream g("dulciuri.out");
  34.  
  35. int q; f >> q;
  36. AIB row(nmax+1), col(nmax+1);
  37. while(q--) {
  38. int type; f >> type;
  39. if(type == 1) {
  40. int x, val; f >> x >> val;
  41. col.update(x+1, val);
  42. cs[x] += val;
  43. }
  44. else if(type == 2) {
  45. int y, val; f >> y >>val;
  46. row.update(y+1, val);
  47. rs[y] += val;
  48. }
  49. else if(type == 3) {
  50. int x1, y1, x2, y2; f >> x1 >> y1 >> x2 >> y2;
  51. if(x1 > x2) swap(x1, x2);
  52. if(y1 > y2) swap(y1, y2);
  53. long double r, c;
  54. if(y2 == y1)
  55. r = rs[y1];
  56. else
  57. r = 1.00 * (row.query(y2) - row.query(y1)) / (y2 - y1);
  58. if(x2 == x1)
  59. c = cs[x1];
  60. else
  61. c = 1.00 * (col.query(x2) - col.query(x1)) / (x2 - x1);
  62.  
  63. g << fixed << setprecision(10) << r + c << "\n";
  64. }
  65. }
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement