Pagini recente » Cod sursa (job #1231298) | Cod sursa (job #1549263) | Cod sursa (job #1154782) | Cod sursa (job #1394953) | Cod sursa (job #3258984)
#include <fstream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;
ifstream fin("baruri.in");
ofstream fout("baruri.out");
int main()
{
int T;
fin >> T;
while (T--)
{
int N;
fin >> N;
vector<int> friends(N + 1, 0);
for (int i = 1; i <= N; ++i)
{
fin >> friends[i];
}
int M;
fin >> M;
while (M--)
{
int op;
fin >> op;
if (op == 0)
{
int B, D;
fin >> B >> D;
int totalFriends = 0;
int start = max(1, B - D);
int end = min(N, B + D);
for (int i = start; i <= end; ++i)
{
if (i != B)
{
totalFriends += friends[i];
}
}
fout << totalFriends << "\n";
}
else if (op == 1)
{
int X, B;
fin >> X >> B;
friends[B] += X;
}
else if (op == 2)
{
int X, B;
fin >> X >> B;
friends[B] -= X;
}
else if (op == 3)
{
int X, B1, B2;
fin >> X >> B1 >> B2;
friends[B1] -= X;
friends[B2] += X;
}
}
}
return 0;
}