Pagini recente » Cod sursa (job #2448648) | Cod sursa (job #2227071) | Cod sursa (job #1032400) | Cod sursa (job #155150) | Cod sursa (job #1950549)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("datorii.in");
ofstream fout ("datorii.out");
const int N = 15005;
int binaryArbore[N];
int totalNumbers, totalQuestions;
void update(int position, int value){
for ( ; position <= totalNumbers; position += position&(-position) )
binaryArbore[position] += value;
}
int query(int position){
int sum = 0;
for ( ; position; position -= position&(-position) )
sum += binaryArbore[position];
return sum;
}
inline void readVariables(){
fin >> totalNumbers >> totalQuestions;
int number;
for ( int index = 1; index <= totalNumbers; index++ ){
fin >> number;
update(index, number);
}
}
inline void solveProblem(){
int operation, first, second;
for ( ; totalQuestions; totalQuestions-- ){
fin >> operation >> first >> second;
switch (operation){
case 0:
update(first, -second);
break;
case 1:
if (first < second)
swap(first, second);
first = query(first);
second = query(second-1);
fout << first - second << "\n";
break;
}
}
}
int main(){
readVariables();
solveProblem();
return 0;
}