记录编号 |
316493 |
评测结果 |
AAAAAAAAA |
题目名称 |
数列操作B |
最终得分 |
100 |
用户昵称 |
sxysxy |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.207 s |
提交时间 |
2016-10-06 20:38:57 |
内存使用 |
0.94 MiB |
显示代码纯文本
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdarg>
#include <string>
using namespace std;
typedef long long LL;
#define MAXN 100002
LL lazy[1000];
LL moni[MAXN];
int magic;
inline LL fast_read()
{
LL r;
bool sig = false;
char ch;
while(ch = getchar())
{
if(ch >= '0' && ch <= '9')
{
r = ch^0x30;
break;
}else if(ch == '-')sig = true;
}
while(isdigit(ch = getchar()))
r = (r<<3)+(r<<1)+(ch^0x30);
return sig? -r:r;
}
void add(int l, int r, int v)
{
for(int i = l; i <= r;)
{
if(i % magic == 0 && i + magic -1 <= r)
{
lazy[i/magic] += v;
i += magic;
}else
{
moni[i] += v;
i++;
}
}
}
LL query(int p)
{
int m = p/magic;
return lazy[m]+moni[p];
}
void clear(int t)
{
while(t--)getchar();
}
int main()
{
freopen("shulieb.in", "r", stdin);
freopen("shulieb.out", "w", stdout);
int n;
n = (int)fast_read();
for(int i = 1; i <= n; i++)moni[i] = fast_read();
int m = (int)fast_read();
magic = (int)sqrt(n);
while(m--)
{
char c;
while(c = getchar())if(c == 'Q' || c == 'A')break;
if(c == 'Q')
{
clear(4);
int p = (int)fast_read();
printf("%lld\n", query(p));
}else
{
clear(2);
int l, r;
l = (int)fast_read();
r = (int)fast_read();
LL v = fast_read();
add(l, r, v);
}
}
return 0;
}