Pagini recente » Cod sursa (job #2638732) | Cod sursa (job #1687653) | Cod sursa (job #1905566) | Cod sursa (job #1053471) | Cod sursa (job #2154637)
#include <fstream>
#include <stdio.h>
using namespace std;
//ifstream fin("aib.in");
ofstream fout("aib.out");
int n, m;
int a[100002];
FILE* f;
void read_data()
{
fscanf(f, "%d %d", &n, &m);
for(int i=1; i<=n; i++)
fscanf(f, "%d", &a[i]);
}
int main()
{
f=fopen("aib.in", "r");
read_data();
for(int i=1; i<=m; i++)
{
int op=-1;
int x=0, y=0;
fscanf(f, "%d", &op);
if(op!=2)
{
fscanf(f, "%d %d", &x, &y);
}
else
{
fscanf(f, "%d", &x);
}
if(op==0)
{
a[x]+=y;
}
else if(op==1)
{
int s=0;
for(int i=x; i<=y; i++)
s+=a[i];
fout << s << '\n';
}
else if(op==2)
{
int s=0;
for(int i=1; i<=n; i++)
{
s+=a[i];
if(s==x)
{
fout << i << '\n';
break;
}
if(s>x)
{
fout << "-1" << '\n';
}
}
}
}
return 0;
}