讨论区翻到的数据都能过,but only 10 分,求Hack,或有好心人帮忙调一调/kk
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define l(x) (x<<1)
#define r(x) (x<<1|1)
#define mpr make_pair
mt19937_64 ra(time(0) ^ (*new char));
//ios::sync_with_stdio(false);
//cin.tie(0); cout.tie(0);
const ll SIZE = 4000005;
const ll mod = 998244353;
ll n, T;
ll ch[SIZE][2], rnd[SIZE], val[SIZE], tag[SIZE], siz[SIZE], flip[SIZE], sum[SIZE], Max[SIZE], prMax[SIZE], nxMax[SIZE], tot;
bool upd[SIZE];
ll rt;
inline ll rd(){
ll x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
if(ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
x = (x<<1) + (x<<3) + (ch^48);
ch = getchar();
}
return x*f;
}
ll power(ll x, ll y){
ll jl = 1;
while(y){
if(y & 1) jl = (jl * x) % mod;
x = (x * x) % mod;
y >>= 1;
}
return jl;
}
ll New(ll xx){
val[++tot] = xx; sum[tot] = Max[tot] = prMax[tot] = nxMax[tot] = xx;
siz[tot] = 1; tag[tot] = 0; upd[tot] = 0; flip[tot] = 0;
rnd[tot] = ra();
ch[tot][0]= ch[tot][1] = 0;
return tot;
}
void pushup(ll p){
siz[p] = siz[ch[p][0]] + siz[ch[p][1]] + 1;
sum[p] = sum[ch[p][0]] + sum[ch[p][1]] + val[p];
Max[p] = max(max(Max[ch[p][0]], Max[ch[p][1]]), max(nxMax[ch[p][0]], 0ll)+val[p]+max(prMax[ch[p][1]], 0ll));
prMax[p] = max(prMax[ch[p][0]], sum[ch[p][0]]+val[p]+max(prMax[ch[p][1]], 0ll));
nxMax[p] = max(nxMax[ch[p][1]], sum[ch[p][1]]+val[p]+max(nxMax[ch[p][0]], 0ll));
}
void pushdown(ll p){
if(upd[p]){
if(ch[p][0]){
upd[ch[p][0]] = 1; tag[ch[p][0]] = tag[p]; val[ch[p][0]] = tag[p];
sum[ch[p][0]] = siz[ch[p][0]] * tag[p];
if(tag[p] > 0) Max[ch[p][0]] = prMax[ch[p][0]] = nxMax[ch[p][0]] = siz[ch[p][0]] * tag[p];
else Max[ch[p][0]] = prMax[ch[p][0]] = nxMax[ch[p][0]] = tag[p];
}
if(ch[p][1]){
upd[ch[p][1]] = 1; tag[ch[p][1]] = tag[p]; val[ch[p][1]] = tag[p];
sum[ch[p][1]] = siz[ch[p][1]] * tag[p];
if(tag[p] > 0) Max[ch[p][1]] = prMax[ch[p][1]] = nxMax[ch[p][1]] = siz[ch[p][1]] * tag[p];
else Max[ch[p][1]] = prMax[ch[p][1]] = nxMax[ch[p][1]] = tag[p];
}
upd[p] = 0; tag[p] = 0;
}
if(flip[p]){
swap(ch[p][0], ch[p][1]);
swap(prMax[p], nxMax[p]);
if(ch[p][0]) flip[ch[p][0]] ^= 1;
if(ch[p][1]) flip[ch[p][1]] ^= 1;
flip[p] = 0;
}
}
void split(ll now, ll k, ll &x, ll &y){
if(!now){
x = y = 0;
return;
}
pushdown(now);
if(siz[ch[now][0]] < k){
x = now;
split(ch[now][1], k-siz[ch[now][0]]-1, ch[now][1], y);
}
else{
y = now;
split(ch[now][0], k, x, ch[now][0]);
}
pushup(now);
}
ll merge(ll x, ll y){
if(!x || !y) return x+y;
if(rnd[x] <= rnd[y]){
pushdown(x);
ch[x][1] = merge(ch[x][1], y);
pushup(x);
return x;
}
else{
pushdown(y);
ch[y][0] = merge(x, ch[y][0]);
pushup(y);
return y;
}
}
void OUT(int now){
if(!now) return;
pushdown(now);
OUT(ch[now][0]);
printf("%lld ", val[now]);
OUT(ch[now][1]);
}
int main(){
// freopen("P2042_2.in", "r", stdin);
// freopen("My.out", "w", stdout);
n = rd(), T = rd();
for(ll i = 1; i <= n; i++){
ll x = rd();
rt = merge(rt, New(x));
}
Max[0] = prMax[0] = nxMax[0] = -(1ll<<60);
while(T--){
char ch[20];
cin >> ch+1;
ll x, y, z;
if(ch[1] == 'I'){
ll id = rd(), zz = rd();
split(rt, id, x, y);
for(ll i = 1; i <= zz; i++){
ll xx = rd();
x = merge(x, New(xx));
}
rt = merge(x, y);
}
else if(ch[1] == 'D'){
ll id = rd(), zz = rd();
split(rt, id-1, x, y);
split(y, zz, y, z);
rt = merge(x, z);
}
else if(ch[3] == 'K'){
ll id = rd(), zz = rd(), c = rd();
split(rt, id-1, x, y);
split(y, zz, y, z);
upd[y] = 1; tag[y] = c; val[y] = c;
sum[y] = siz[y] * c;
if(c > 0) Max[y] = prMax[y] = nxMax[y] = siz[y] * c;
else Max[y] = prMax[y] = nxMax[y] = c;
rt = merge(x, merge(y, z));
}
else if(ch[1] == 'R'){
ll id = rd(), zz = rd();
split(rt, id-1, x, y);
split(y, zz, y, z);
flip[y] ^= 1;
rt = merge(x, merge(y, z));
}
else if(ch[1] == 'G'){
ll id = rd(), zz = rd();
split(rt, id-1, x, y);
split(y, zz, y, z);
printf("%lld\n", sum[y]);
rt = merge(x, merge(y, z));
}
else{
printf("%lld\n", Max[rt]);
}
// OUT(rt);
// cout << endl;
}
return 0;
}
/*
9 12
2 -6 3 5 1 -5 -3 6 3
GET-SUM 5 4
MAX-SUM
INSERT 8 3 -5 7 2
DELETE 12 1
MAKE-SAME 3 3 2
REVERSE 3 6
GET-SUM 5 4
MAX-SUM
Reserve 3 5
Delete 4 4
MAX_SUM
GET-SUM 4 0
*/