记录编号 |
406698 |
评测结果 |
AAAAAAAAAAAAAAA |
题目名称 |
数列操作B |
最终得分 |
100 |
用户昵称 |
kZime |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.818 s |
提交时间 |
2017-05-19 19:17:02 |
内存使用 |
0.70 MiB |
显示代码纯文本
# include <bits/stdc++.h>
# define MAXN 100023
using namespace std;
inline int gn() {
int k = 0, f = 1;
char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
for(; isdigit(c); c = getchar()) k = k * 10 + c - '0';
return k * f;
}
int a[MAXN], n, m;
struct node {
int lz, l, r;
node *ls, *rs;
node() {
lz = 0;
ls = rs = NULL;
}
}*root;
node *build(int l, int r) {
int mid = (l + r) >> 1;
node *x = new node();
x->l = l;
x->r = r;
if(l == r) return x;
x->ls = build(l, mid);
x->rs = build(mid + 1, r);
return x;
}
inline void push_down(node *x) {
if(x->l == x->r) {
a[x->l] += x->lz;
x->lz = 0;
} else {
x->ls->lz += x->lz;
x->rs->lz += x->lz;
x->lz = 0;
}
}
void change(node *x, int s, int t, int k) {
push_down(x);
if(x->l == s && x->r == t) {
x->lz += k;
} else {
int mid = (x->l + x->r) >> 1;
if(t <= mid) change(x->ls, s, t, k);
else if(s > mid) change(x->rs, s, t, k);
else {
change(x->ls, s, mid, k);
change(x->rs, mid + 1, t, k);
}
}
}
int query(node *x, int p) {
push_down(x);
if(x->l == x->r) {
return a[x->l];
} else {
int mid = (x->l + x->r) >> 1;
if(p <= mid) return query(x->ls, p);
else return query(x->rs, p);
}
}
int main() {
freopen("shulieb.in", "r", stdin);
freopen("shulieb.out", "w", stdout);
n = gn();
for(int i = 1; i <= n; i++) a[i] = gn();
root = build(1, n);
m = gn();
while(m--) {
char op[6];
scanf("%s", op);
if(op[0] == 'Q') {
printf("%d\n", query(root, gn()));
} else {
int s = gn();
int t = gn();
int k = gn();
change(root, s, t, k);
}
}
}