Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- const int nmax = 1e6;
- ll cs[nmax+5], rs[nmax+5];
- struct AIB {
- inline int lsb(int x) {
- return x & (-x);
- }
- vector<ll> v;
- int len = 0;
- AIB(int n) {
- v.resize(n+1, 0);
- len = n;
- }
- void update(int pos, ll val) {
- for(int i=pos; i<=len; i+=lsb(i))
- v[i] += val;
- }
- ll query(int pos) {
- ll temp = 0;
- for(int i=pos; i>=1; i-=lsb(i))
- temp += v[i];
- return temp;
- }
- };
- int main() {
- ifstream f("dulciuri.in");
- ofstream g("dulciuri.out");
- int q; f >> q;
- AIB row(nmax+1), col(nmax+1);
- while(q--) {
- int type; f >> type;
- if(type == 1) {
- int x, val; f >> x >> val;
- col.update(x+1, val);
- cs[x] += val;
- }
- else if(type == 2) {
- int y, val; f >> y >>val;
- row.update(y+1, val);
- rs[y] += val;
- }
- else if(type == 3) {
- int x1, y1, x2, y2; f >> x1 >> y1 >> x2 >> y2;
- if(x1 > x2) swap(x1, x2);
- if(y1 > y2) swap(y1, y2);
- long double r, c;
- if(y2 == y1)
- r = rs[y1];
- else
- r = 1.00 * (row.query(y2) - row.query(y1)) / (y2 - y1);
- if(x2 == x1)
- c = cs[x1];
- else
- c = 1.00 * (col.query(x2) - col.query(x1)) / (x2 - x1);
- g << fixed << setprecision(10) << r + c << "\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement