Pagini recente » Statistici hgdsjagjsdhajhgsda (hgdsjagjsdhajhgsda) | Cod sursa (job #1551698) | Istoria paginii utilizator/kaziploaie | Istoria paginii runda/sm | Cod sursa (job #1164664)
/*
Keep It Simple!
*/
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include<cstdio>
#define MaxN 100005
int Aib[MaxN],N,M;
void Add(int position, int value)
{
while (position <= N)
{
Aib[position] += value;
position += (position & -position);
}
}
int Sum(int position)
{
int S = 0;
while (position)
{
S += Aib[position];
position -= (position & -position);
}
return S;
}
int FirstSum(int value)
{
int position = 1;
while (Aib[position] != value && position <= N)
position *= 2;
if (Aib[position] == value)
return position;
else
return -1;
}
int main()
{
freopen("aib.in", "r", stdin);
freopen("aib.out", "w", stdout);
scanf("%d%d", &N, &M);
int x,y,type;
for (int i = 1; i <= N; i++)
{
scanf("%d", &x);
Add(i, x);
}
for (int i = 1; i <= M; i++)
{
scanf("%d", &type);
if (type == 0)
{
scanf("%d%d", &x, &y);
Add(x, y);
}
else if (type == 1)
{
scanf("%d%d", &x, &y);
printf("%d\n", Sum(y) - Sum(x - 1));
}
else if (type == 2)
{
scanf("%d", &x);
printf("%d\n",FirstSum(x));
}
}
}