Pagini recente » Cod sursa (job #3139063) | Cod sursa (job #2488907) | Cod sursa (job #2249951) | Cod sursa (job #2757301) | Cod sursa (job #2871892)
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
ifstream fin("dulciuri.in");
ofstream fout("dulciuri.out");
const int NMAX = 1e6;
double aibLin[NMAX + 1], aibCol[NMAX + 1];
void updAib(double aib[], int pos, double delta);
double queryAib(double aib[], int pos);
int main()
{
int nrq, x1, y1, x2, y2, tp, x, y;
double val, divi;
fin >> nrq;
for (int i = 0; i < nrq; i++) {
fin >> tp;
if (tp == 1) {
fin >> x >> val;
updAib(aibCol, x, val);
}
else if (tp == 2) {
fin >> y >> val;
updAib(aibLin, y, val);
}
else {
fin >> x1 >> y1 >> x2 >> y2;
val = 0;
divi = x1 - x2;
if (divi < 0)
divi = -divi;
if (divi == 0)
divi = 1;
val += (queryAib(aibCol, max(x1, x2)) - queryAib(aibCol, min(x1, x2) - 1)) / divi;
divi = y1 - y2;
if (divi < 0)
divi = -divi;
if (divi == 0)
divi = 1;
val += (queryAib(aibLin, max(y1, y2)) - queryAib(aibLin, min(y1, y2) - 1)) / divi;
fout << setprecision(15) << val << '\n';
}
}
return 0;
}
void updAib(double aib[], int pos, double delta) {
for (; pos <= NMAX; pos += (pos & -pos))
aib[pos] += delta;
}
double queryAib(double aib[], int pos) {
double s = 0;
for (; pos > 9; pos -= (pos & -pos))
s += aib[pos];
return s;
}