1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| #pragma region revive #include <set> #include <map> #include <cmath> #include <queue> #include <stack> #include <bitset> #include <cstdio> #include <vector> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <unordered_map> #define inl inline #define re register int #define fa(x) t[x].fa #define son(x,y) t[x].child[y] #define ls(x) t[x].child[0] #define rs(x) t[x].child[1] #define ll long long const int inf = 0x3f3f3f3f; #define lowbit(x) ((x) & (-x)) using namespace std; #ifndef _DEBUG #define getchar() (*(IOB.in.p++)) #define putchar(c) (*(IOB.out.p++)=(c)) #define io_eof() (IOB.in.p>=IOB.in.pend) struct IOBUF { struct { char buff[1 << 26], *p, *pend; }in; struct { char buff[1 << 26], *p; }out; IOBUF() { in.p = in.buff; out.p = out.buff; in.pend = in.buff + fread(in.buff, 1, 1 << 26, stdin); }~IOBUF() { fwrite(out.buff, 1, out.p - out.buff, stdout); } }IOB; #endif template<typename IO> inl void write(IO x) { if (x == 0) return (void)putchar('0'); if (x < 0)putchar('-'), x = -x; static char buf[30]; char* p = buf; while (x) { *(p++) = x % 10 + '0'; x /= 10; } while (p > buf)putchar(*(--p)); } inl void writestr(const char *s) { while (*s != 0)putchar(*(s++)); } template<typename IO>inl void writeln(IO x) { write(x), putchar('\n'); } template<typename IO>inl void writesp(IO x) { write(x), putchar(' '); } inl int readstr(char *s) { char *begin = s, c = getchar(); while (c < 33 || c>127) { c = getchar(); } while (c >= 33 && c <= 127) { *(s++) = c; c = getchar(); } *s = 0; return s - begin; } template<typename IO> inl IO read() { IO x = 0; register bool w = 0; register char c = getchar(); while (c > '9' || c < '0') { if (c == '-') w = 1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); } return w ? -x : x; } #pragma endregion #undef ls #undef rs #define ls(x) ((x)<<1) #define rs(x) (ls(x)|1) struct node { int lsum, rsum, sum, tot; }t[10000001]; node operator +(const node &a, const node &b) { node c; c.tot = a.tot + b.tot; c.lsum = max(a.lsum, b.lsum + a.tot); c.rsum = max(b.rsum, a.rsum + b.tot); c.sum = max({ a.sum,b.sum,a.rsum + b.lsum }); return c; } int a[1000001]; inl void maintain(int x) { t[x] = t[ls(x)] + t[rs(x)]; } inl void change(int k, int l, int r, int p, int w) { if (l == r) return (void)(t[k].tot = t[k].sum = t[k].lsum = t[k].rsum = w); re mid = l + r >> 1; if (p <= mid)change(ls(k), l, mid, p, w); else change(rs(k), mid + 1, r, p, w); maintain(k); } inl void build(int k, int l, int r) { if (l == r) return (void)(t[k].tot = t[k].sum = t[k].lsum = t[k].rsum = a[l]); re mid = l + r >> 1; build(ls(k), l, mid), build(rs(k), mid + 1, r); maintain(k); } inl node query(int k, int l, int r, int x, int y) { if (l >= x && r <= y)return t[k]; re mid = l + r >> 1; node ans = { 0,0,0,0 }; if (x <= mid) { ans = query(ls(k), l, mid, x, y); if (y > mid)ans = ans + query(rs(k), mid + 1, r, x, y); } else if (y > mid)ans = query(rs(k), mid + 1, r, x, y); return ans; } signed main() { re n = read<int>(), m = read<int>(), op, x, y; for (re i = 1; i <= n; i++)a[i] = read<int>(); build(1, 1, n); while (m--) { op = read<int>(), x = read<int>(), y = read<int>(); if (op == 1) { if (x > y)swap(x, y); writeln(query(1, 1, n, x, y).sum); } else change(1, 1, n, x, y); } }
|