比赛 |
cdcqの省选膜你赛 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
新史「新幻想史 -现代史-」 |
最终得分 |
100 |
用户昵称 |
confoo |
运行时间 |
5.881 s |
代码语言 |
C++ |
内存使用 |
11.74 MiB |
提交时间 |
2017-04-11 21:04:38 |
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <cctype>
#define lch (o<<1)
#define rch ((o<<1)|1)
#define mid ((l + r) >> 1)
#define file(x) "cdcq_a."#x
typedef long long ll;
const int N = 50010, V = N << 2;
int n, m, out;
ll val[V], adv[V], ans[V];
char buf[2];
inline void mkadv(int o, int l, int r, ll v) {
if (o) val[o] += v*(r - l + 1), adv[o] += v;
}
inline void down(int o, int l, int r) {
if (adv[o]) mkadv(lch, l, mid, adv[o]), mkadv(rch, mid + 1, r, adv[o]), adv[o] = 0;
}
void add(int o, int l, int r, int q1, int q2, int v) {
if (q1 <= l && r <= q2) mkadv(o, l, r, v);
else {
down(o, l, r);
if (q1 <= mid) add(lch, l, mid, q1, q2, v);
if (mid < q2) add(rch, mid + 1, r, q1, q2, v);
val[o] = val[lch] + val[rch];
}
}
ll query(int o, int l, int r, int q1, int q2) {
if (q1 <= l && r <= q2) return val[o];
else {
down(o, l, r);
ll ret = 0;
if (q1 <= mid) ret += query(lch, l, mid, q1, q2);
if (mid < q2) ret += query(rch, mid + 1, r, q1, q2);
return ret;
}
}
struct cmd {
int x, t, l1, r1, v1, l2, r2, v2, id;
inline void rd() {
scanf("%s", buf);
if (buf[0] == 'M') scanf("%d%d%d%d%d%d", &l1, &r1, &v1, &l2, &r2, &v2);
else scanf("%d%d", &l1, &r1), id = ++out;
scanf("%d", &t);
x = buf[0] == 'M';
}
inline void aply(int rev = 0) {
rev = rev ? -1 : 1;
if (x == 1) add(1, 1, n, l1, r1, rev*-v1), add(1, 1, n, l2, r2, rev*v2);
else ans[id] += query(1, 1, n, l1, r1);
}
}op[N<<1], tmp[N<<1];
void solve(int l, int r) {
if (l == r) return;
solve(l, mid), solve(mid + 1, r);
for (int i = l, ll = l, rr = mid + 1; ll <= mid || rr <= r; i++) {
if (ll > mid || (rr <= r && op[rr].t < op[ll].t)) {
if (op[rr].x == 0) op[rr].aply();
tmp[i] = op[rr++];
}
else {
if (op[ll].x == 1) op[ll].aply();
tmp[i] = op[ll++];
}
}
for (int i = l; i <= mid; i++) if (op[i].x == 1) op[i].aply(1);
for (int i = l; i <= r; i++) op[i] = tmp[i];
}
int main() {
freopen(file(in), "r", stdin);
freopen(file(out), "w", stdout);
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
int x; scanf("%d", &x);
op[i].x = 1, op[i].l2 = op[i].r2 = i, op[i].v2 = x;
op[i].t = -1;
op[i].l1 = op[i].r1 = 1;
}
for (int i = 1; i <= m; i++) op[n + i].rd();
solve(1, n + m);
for (int i = 1; i <= out; i++) printf("%lld\n", ans[i]);
}