记录编号 |
394119 |
评测结果 |
AAAAAAAAAA |
题目名称 |
数列操作C |
最终得分 |
100 |
用户昵称 |
kZime |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.265 s |
提交时间 |
2017-04-13 00:49:09 |
内存使用 |
31.62 MiB |
显示代码纯文本
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 1e5 + 100;
const long long mod = 4611686018427387904;
inline void File_Read() {
#ifdef DEBUG
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#else
freopen("shuliec.in", "r", stdin);
freopen("shuliec.out", "w", stdout);
#endif
}
inline ll get_num() {
ll 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;
}
//inline void get_char(string &tar) {
// char c = getchar();
// for (;!isalpha(c); c = getchar());
// for (; isalpha(c); c = getchar()) tar = tar + c;
//}
inline char get_char() {
char c = getchar();
for(;!isalpha(c); c = getchar());
char k = c;
for(; isalpha(k); k = getchar());
return c;
}
struct node {
ll l, r, s, lz;
node(){l = 0, r = 0, s = 0, lz = 0;}
ll lth() {
return r - l + 1;
}
}nd[MAXN * 10];
ll a[MAXN], n, q, ti;
void build(ll x, ll l, ll r) {
nd[x].l = l;
nd[x].r = r;
if(l == r) {
nd[x].s = get_num();
return;
}
build(x << 1, l, (l + r) / 2);
build(x << 1 | 1, (l + r) / 2 + 1, r);
nd[x].s = nd[x << 1].s + nd[x << 1 | 1].s;
}
inline void pushdown(ll x) {
if(!nd[x].lz) return;
if(nd[x].l == nd[x].r) {
nd[x].s += nd[x].lz * nd[x].lth();
nd[x].lz = 0;
return;
}
nd[x << 1].lz += nd[x].lz;
nd[x << 1 | 1].lz += nd[x].lz;
nd[x].s += nd[x].lz * nd[x].lth();
nd[x].lz = 0;
}
ll find(ll x, ll l, ll r) {
pushdown(x);
if(nd[x].l == l && nd[x].r == r) {
return nd[x].s;
}
else if(r <= nd[x << 1].r) {
return find(x << 1, l, r);
}
else if(l >= nd[x << 1 | 1].l) {
return find(x << 1 | 1, l, r);
}
else {
return find(x << 1, l, nd[x << 1].r) + find(x << 1 | 1, nd[x << 1 | 1].l, r);
}
}
void add(ll x, ll l, ll r, ll k) {
if(nd[x].l == l && nd[x].r == r) {
nd[x].lz += k;
pushdown(x);
return;
}
else {
nd[x].s += (r - l + 1) * k;
}
if(r <= nd[x << 1].r) {
add(x << 1, l, r, k);
}
else if(l >= nd[x << 1 | 1].l) {
add(x << 1 | 1, l, r, k);
}
else {
add(x << 1, l, nd[x << 1].r, k);
add(x << 1 | 1, nd[x << 1 | 1].l, r, k);
}
}
int main() {
File_Read();
n = get_num();
build(1, 1, n);
q = get_num();
while(q--) {
if(get_char() == 'S') {
ll l = get_num();
ll r = get_num();
printf("%lld\n", find(1, l, r));
}
else {
int l = get_num();
int r = get_num();
int k = get_num();
add(1, l, r, k);
}
}
}