直角,样例都过不了
#include <iostream>
#include <streambuf>
#include <fstream>
namespace AKA
{
#if __cplusplus >= 201103L
using ll = long long;
using ull = unsigned long long;
using lll = __int128;
using dbl = double;
using ldbl = long double;
#else
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
typedef double dbl;
typedef long double ldbl;
#endif
} // namespace AKA
namespace IO
{
using namespace AKA;
std::streambuf* inbuf, *outbuf;
char ibuf[1 << 23 | 1], *i1 = ibuf, *i2 = ibuf;
char outstk[105];
int top = 0;
inline char gc() { return (i1 == i2 && (i2 = (i1 = ibuf) + inbuf->sgetn(ibuf, 1 << 23), i1 == i2) ? EOF : *i1++); }
inline void pc(char x) { outbuf->sputc(x); }
inline int iget() { int x = 0; bool f = false; char c = gc(); while (c < '0' || c > '9') { f |= c == '-'; c = gc(); } while (c >= '0' && c <= '9') { x = (x << 3) + (x << 1) + (c ^ 48); c = gc(); } return f ? -x : x; }
inline void ipr(int x) { if (x == 0) { pc('0'); return ; } if (x < 0) { pc('-'); x = -x; } top = 0; while (x) { outstk[top++] = x % 10 + 48; x /= 10; } while (top--) { pc(outstk[top]); } }
inline void iwsp(int x) { ipr(x); pc(' '); }
inline void iwln(int x) { ipr(x); pc('\n'); }
inline ll llget() { ll x = 0; bool f = false; char c = gc(); while (c < '0' || c > '9') { f |= c == '-'; c = gc(); } while (c >= '0' && c <= '9') { x = (x << 3) + (x << 1) + (c ^ 48); c = gc(); } return f ? -x : x; }
inline void llpr(ll x) { if (x == 0) { pc('0'); return ; } if (x < 0) { pc('-'); x = -x; } top = 0; while (x) { outstk[top++] = x % 10 + 48; x /= 10; } while (top--) { pc(outstk[top]); } }
inline void llwsp(ll x) { llpr(x); pc(' '); }
inline void llwln(ll x) { llpr(x); pc('\n'); }
inline ull ullget() { ll x = 0; bool f = false; char c = gc(); while (c < '0' || c > '9') { f |= c == '-'; c = gc(); } while (c >= '0' && c <= '9') { x = (x << 3) + (x << 1) + (c ^ 48); c = gc(); } return f ? -x : x; }
inline void ullpr(ull x) { if (x == 0) { pc('0'); return ; } if (x < 0) { pc('-'); x = -x; } top = 0; while (x) { outstk[top++] = x % 10 + 48; x /= 10; } while (top--) { pc(outstk[top]); } }
inline void ullwsp(ull x) { ullpr(x); pc(' '); }
inline void ullwln(ull x) { ullpr(x); pc('\n'); }
inline void spr(const char* s) { char* t = const_cast<char*>(s); while (*t && (pc(*t++), true)) {} }
inline void swsp(const char* s) { spr(s); pc(' '); }
inline void swln(const char* s) { spr(s); pc('\n'); }
template<typename _Tp> inline void iget(_Tp& x) { x = 0; bool f = false; char c = gc(); while (c < '0' || c > '9') { f |= c == '-'; c = gc(); } while (c >= '0' && c <= '9') { x = (x << 3) + (x << 1) + (c ^ 48); c = gc(); } f && (x = -x); }
template<typename _Tp, typename ... Args> inline void iget(_Tp& x, Args& ... args) { iget(x), iget(args ...); }
template<typename _Tp> inline void pr(_Tp x) { if (x == 0) { pc('0'); return ; } if (x < 0) { pc('-'); x = -x; } top = 0; while (x) { outstk[top++] = x % 10 + 48; x /= 10; } while (top--) { pc(outstk[top]); } }
template<typename _Tp, typename ... Args> inline void pr(_Tp x, Args ... args) { pr(x), pr(args ...); }
template<typename _Tp> inline void wsp(_Tp x) { pr(x), pc(' '); }
template<typename _Tp, typename ... Args> inline void wsp(_Tp x, Args ... args) { wsp(x), wsp(args ...); }
}
#include <random>
namespace Solution
{
std::ifstream cin;
std::ofstream cout;
using namespace AKA;
using IO::gc; using IO::pc;
using IO::iget; using IO::ipr; using IO::iwsp; using IO::iwln;
using IO::llget; using IO::llpr; using IO::llwsp; using IO::llwln;
using IO::ullget; using IO::ullwsp; using IO::ullwln;
using IO::spr; using IO::swsp; using IO::swln;
using IO::pr; using IO::wsp;
#define flp(name, lpst, lped) for (int name = lpst, name##end = lped; name <= name##end; ++name)
#define plf(name, lpst, lped) for (int name = lpst, name##end = lped; name >= name##end; --name)
constexpr int maxn = 6e5 + 5;
std::uniform_int_distribution<int> lim(1, maxn + maxn + maxn + maxn);
std::mt19937 ri(std::random_device{}());
int stk[maxn], top;
struct Node
{
int pri, ls, rs, size, val, cov, sum, maxl, maxr, max;
bool lrev, lcov;
} tr[maxn];
int rt;
inline int mk(int k)
{
int x = stk[top--];
tr[x].pri = lim(ri);
tr[x].ls = tr[x].rs = tr[x].lcov = tr[x].lrev = 0;
tr[x].size = 1;
tr[x].val = tr[x].sum = k;
tr[x].maxl = tr[x].maxr = std::max(0, k);
tr[x].max = k;
return x;
}
inline void push_up(int x)
{
if (!x)
{
return ;
}
tr[x].size = tr[tr[x].ls].size + tr[tr[x].rs].size + 1;
tr[x].sum = tr[tr[x].ls].sum + tr[tr[x].rs].sum + tr[x].val;
tr[x].maxl = std::max(0, std::max(tr[tr[x].ls].maxl, tr[tr[x].ls].sum + tr[x].val + tr[tr[x].rs].maxl));
tr[x].maxr = std::max(0, std::max(tr[tr[x].rs].maxr, tr[tr[x].rs].sum + tr[x].val + tr[tr[x].ls].maxr));
if (tr[x].ls)
{
tr[x].max = std::max(tr[x].max, tr[tr[x].ls].max);
}
if (tr[x].rs)
{
tr[x].max = std::max(tr[x].max, tr[tr[x].rs].max);
}
}
inline void rev(int x)
{
if (!x)
{
return ;
}
std::swap(tr[x].ls, tr[x].rs);
std::swap(tr[x].maxl, tr[x].maxr);
tr[x].lrev ^= 1;
}
inline void cov(int x, int k)
{
tr[x].val = tr[x].cov = k;
tr[x].sum = tr[x].size * k;
tr[x].maxl = tr[x].maxr = std::max(0, tr[x].sum);
tr[x].max = std::max(k, tr[x].sum);
tr[x].lcov = 1;
}
inline void push_down(int x)
{
if (!x)
{
return ;
}
if (tr[x].lrev)
{
tr[x].ls && (rev(tr[x].ls), true);
tr[x].rs && (rev(tr[x].rs), true);
tr[x].lrev = 0;
}
if (tr[x].lcov)
{
tr[x].ls && (cov(tr[x].ls, tr[x].cov), true);
tr[x].rs && (cov(tr[x].rs, tr[x].cov), true);
tr[x].cov = tr[x].lcov = 0;
}
}
void del(int x)
{
if (!x)
{
return ;
}
stk[++top] = x;
tr[x].ls && (del(tr[x].ls), true);
tr[x].rs && (del(tr[x].rs), true);
}
void split(int now, int k, int& x, int& y)
{
now && (push_down(now), true);
if (!now)
{
x = y = 0;
return ;
}
if (tr[tr[now].ls].size + 1 <= k)
{
x = now;
split(tr[now].rs, k - tr[tr[now].ls].size - 1, tr[x].rs, y);
}
else
{
y = now;
split(tr[now].ls, k, x, tr[y].ls);
}
push_up(now);
}
int merge(int x, int y)
{
if (!x || !y)
{
return x ^ y;
}
if (tr[x].pri < tr[y].pri)
{
push_down(x);
tr[x].rs = merge(tr[x].rs, y);
push_up(x);
return x;
}
else
{
push_down(y);
tr[y].ls = merge(x, tr[y].ls);
push_up(y);
return y;
}
return 0;
}
int a[maxn];
int build(int l, int r)
{
if (l == r)
{
return mk(a[l]);
}
int mid = l + ((r - l) >> 1);
return merge(build(l, mid), build(mid + 1, r));
}
#define db(x) (std::cerr << x << std::endl)
void main(void)
{
std::ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
cin.open("main.in"), cout.open("main.out");
IO::inbuf = cin.rdbuf(); IO::outbuf = cout.rdbuf();
#else
using std::cin; using std::cout;
#if __cplusplus >= 201103L
cin.tie(nullptr); cout.tie(nullptr);
#else
cin.tie(NULL); cout.tie(NULL);
#endif
IO::inbuf = cin.rdbuf(); IO::outbuf = cout.rdbuf();
#endif
int n, general_q; iget(n, general_q);
flp (i, 1, 500000)
{
stk[++top] = i;
}
flp (i, 1, n)
{
a[i] = iget();
}
rt = merge(rt, build(1, n));
// db(1);
while (general_q--)
{
std::string op;
char c; while ((c = gc()) < 'A' || c > 'Z') {}
while ((c >= 'A' && c <= 'Z') || c == '-') { op += c; c = gc(); }
int x, y, z;
// db(op);
if (op[0] == 'I')
{
int pos, tot; iget(pos, tot);
split(rt, pos, x, y);
flp (i, 1, tot)
{
a[i] = iget();
}
rt = merge(merge(x, build(1, tot)), y);
// db(1);
}
else if (op[0] == 'D')
{
int pos, tot; iget(pos, tot);
split(rt, pos - 1, x, y);
split(y, tot, y, z);
del(y);
rt = merge(x, z);
// db(2);
}
else if (op[0] == 'M' && op[2] == 'K')
{
int pos, tot, k; iget(pos, tot, k);
split(rt, pos - 1, x, y);
split(y, tot, y, z);
cov(y, k);
rt = merge(merge(x, y), z);
// db(3);
}
else if (op[0] == 'R')
{
int pos, tot; iget(pos, tot);
split(rt, pos - 1, x, y);
split(y, tot, y, z);
rev(y);
rt = merge(merge(x, y), z);
// db(4);
}
else if (op[0] == 'G')
{
int pos, tot; iget(pos, tot);
split(rt, pos - 1, x, y);
split(y, tot, y, z);
iwln(tr[y].sum);
rt = merge(merge(x, y), z);
// db(5);
}
else if (op[0] == 'M' && op[2] == 'X')
{
iwln(tr[rt].max);
// db(6);
}
}
#ifndef ONLINE_JUDGE
cin.close(); cout.close();
#endif
}
} // namespace Solution
int main(int argc, const char* argv[])
{
Solution::main();
return 0;
}