之前的笔记丢失了
改日再填
#include<cstdio>
#include<ctime>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int n, m, ot;
long long gg;
long long ans[500005];
struct opt
{
int t, x;
long long k;
opt(int a = 0, int b = 0, long long c = 0)
{
t = a;
x = b;
k = c;
}
bool operator < (const opt &o) const
{
return (x == o.x) ? t < o.t : x < o.x;
}
}o[1500005], e[1500005];
long long sum;
int p, q, tot;
void cdq(int L, int R)
{
if (L >= R) return;
int Mid = L + R >> 1;
cdq(L, Mid);
cdq(Mid + 1, R);
sum = 0;
p = L, q = Mid + 1, tot = L;
while (p <= Mid && q <= R)
{
if (o[p] < o[q])
{
if (o[p].t == 1) sum += o[p].k;
e[tot++] = o[p++];
}
else
{
if (o[q].t == 2) ans[o[q].k] -= sum;
if (o[q].t == 3) ans[o[q].k] += sum;
e[tot++] = o[q++];
}
}
while (p <= Mid)
{
e[tot++] = o[p++];
}
while (q <= R)
{
if (o[q].t == 2) ans[(int)o[q].k] -= sum;
if (o[q].t == 3) ans[(int)o[q].k] += sum;
e[tot++] = o[q++];
}
for (int i = L; i <= R; ++i)
{
o[i] = e[i];
}
}
int y;
long long r;
int main()
{
scanf("%d%d", &n, &m);
for (int a, i = 1; i <= n; ++i)
{
scanf("%lld", &a);
o[++ot] = opt(1, i, a);
}
for (int p, x, i = 1; i <= m; ++i)
{
scanf("%d", &p);
if (p == 1)
{
scanf("%d%lld", &x, &r);
o[++ot] = opt(1, x, r);
}
else
{
scanf("%d%d", &x, &y);
o[++ot] = opt(2, x - 1, 1ll*(++gg));
o[++ot] = opt(3, y, 1ll*gg);
}
}
cdq(1, ot);
for (int i = 1; i <= gg; ++i)
{
printf("%lld\n", ans[i]);
}
return 0;
}