Pagini recente » Cod sursa (job #1050617) | Cod sursa (job #1724556) | Cod sursa (job #3130984) | Cod sursa (job #1380195) | Cod sursa (job #1018893)
#include <fstream>
using namespace std;
int main()
{
const char* file_name = "datorii.in";
const char* file_out = "datorii.out";
int N, M;
ifstream ifs(file_name);
ofstream ofs(file_out);
ifs>>N>>M;
//read the vector
int *a = new int[N+1];
for (int n = 1; n <= N; n++) ifs>>a[n];
//read the operations one by one and process them
for (int m = 1; m <= M; m++)
{
int op_type, X, Y;
ifs>>op_type>>X>>Y;
//process the operations
if (op_type == 0) a[X] -= Y;
else //(op_type == 1)
{
unsigned long long sum = 0;
for (int n = X; n <= Y; n++) sum += a[n];
//write the result to the file
ofs<<sum<<"\n";
}
}
//release the memory
delete[] a;
//close the files
ifs.close();
ofs.close();
return 0;
}