1#include <cstdio>2#include <iostream>3#include <cstring>4#include <cmath>5#include <ctime>6#include <cstdlib>7 8#include <algorithm>9#include <string>Ten#include <stack> One#include <queue> A#include <vector> - - using namespacestd; the - voidAddint,int); - intPreint); - + intc[500010]; - + inti,n,m; A at intT; - - intK; - - intp,x; - intb; in - intMain () { toscanf"%d%d",&n,&m); + - for(i=1; i<=n;i++){ thescanf"%d",&t); * Add (i,t); $ }Panax Notoginseng - for(i=1; i<=m;i++){ thescanf"%d",&k); + if(k==1){ Ascanf"%d%d",&p,&x); the Add (p,x); + } - Else{ $scanf"%d%d",&a,&b); $printf"%d\n", pre (b)-pre (A-1)); - } - } the - return 0;Wuyi } the - voidAddintPintx) { Wu while(p<=N) { -c[p]+=x; Aboutp+=p&-p; $ } - } - - intPreintp) { A intsum=0; + while(p>=1){ thesum+=C[p]; -p-=p&-p; $ } the returnsum; the}
[Template] Valley T3374 Tree Array template 1