记录编号 |
406639 |
评测结果 |
AAAAAAAAAAAAAAA |
题目名称 |
数列操作A |
最终得分 |
100 |
用户昵称 |
HeHe |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.387 s |
提交时间 |
2017-05-19 08:19:46 |
内存使用 |
2.68 MiB |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 1e5 + 10;
inline int in(void){
char tmp = getchar();
int res = 0;
while(!isdigit(tmp)) tmp = getchar();
while(isdigit(tmp))
res = (res + (res << 2) << 1) + (tmp ^ 48),
tmp = getchar();
return res;
}
inline int lowbit(int x);
inline int sum(int x);
inline void update(int i, int k);
int os[MAXN];
int N, Q;
char cmd[5];
void* Main(){
#ifndef LOCAL
freopen("shulie.in", "r", stdin);
freopen("shulie.out", "w", stdout);
#else
freopen("test.in", "r", stdin);
#endif
N = in();
for(int i = 1, n; i <= N; ++i){
n = in();
update(i, n);
}
Q = in();
for(int i = 1, a, b; i <= Q; ++i){
scanf("%s", cmd);
a = in(), b = in();
if(*cmd == 'S') printf("%d\n", sum(b) - sum(a - 1));
else update(a, b);
}
return NULL;
}
void *Main_ = Main();
int main(){;}
inline int lowbit(int x){
return x & (~x + 1);
}
inline int sum(int x){
int sum = 0;
while(x){
sum += os[x];
x -= lowbit(x);
}
return sum;
}
inline void update(int i, int k){
while(i <= N){
os[i] += k;
i += lowbit(i);
}
return ;
}