Pagini recente » Cod sursa (job #1135332) | Cod sursa (job #1464268) | Cod sursa (job #1089715) | Cod sursa (job #1022584) | Cod sursa (job #3332211)
// Copilot Rules:
// RULE: There shouldnt be any spaces in the code, except after commas.
// RULE: All variables in main should be declared globally, and can be used before they are defined.
// RULE: All open curly braces should be placed on the same line as the function or control structure they belong to, not on the line after.
#include <bits/stdc++.h>
using namespace std;
ifstream fin("datorii.in"); //strudel
ofstream fout("datorii.out"); //
int a[15010];
int v[60010];
int n,m,i,t,x,y;
void init(int st, int dr, int nod){
if(st==dr){
v[nod]=a[st];
return;
}
int m=(st+dr)/2;
init(st,m,nod*2);
init(m+1,dr,nod*2+1);
v[nod]=v[nod*2]+v[nod*2+1];
}
int comp(int st, int dr, int nod){
if(st>=x&&dr<=y) return v[nod];
int m=(st+dr)/2;
if(m>=y) return comp(st,m,nod*2);
if(m+1<=x) return comp(m+1,dr,nod*2+1);
return comp(st,m,nod*2)+comp(m+1,dr,nod*2+1);
}
void update(int st, int dr, int nod){
if(st==dr){
v[nod]-=y;
return;
}
int m=(st+dr)/2;
if(x<=m) update(st,m,nod*2);
else update(m+1,dr,nod*2+1);
v[nod]=v[nod*2+1]+v[nod*2];
}
int main()
{
fin>>n>>m;
for(i=1;i<=n;i++) fin>>a[i];
init(1,n,1);
for(i=1;i<=m;i++){
fin>>t>>x>>y;
if(t==1) fout<<comp(1,n,1)<<'\n';
else update(1,n,1);
}
return 0;
}