?为什么编译器可以跑到牛客就段错误
rt,J
#include<bits/stdc++.h>
using namespace std;
#define itn int
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, int> PLI;
typedef pair<int, ll> PIL;
typedef pair<ll, ll> PLL;
#define x first
#define y second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define lep(i,a,b) for(int i=(a);i>=(b);i--)
#define sci(x) cin >> (x)
#define pri(x) cout << (x) << " ";
#define prl(x) cout << (x) << endl;
#define pli(x) cout << (x) << " ";
#define pll(x) cout << (x) << endl;
#define mem(a, x) memset(a, x, sizeof a)
#define mep(a, x) memcpy(a, x, sizeof x)
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define ls u << 1
#define rs u << 1 | 1
//printf("case:%d %d\n", );
const int N = 3e5 + 10;
int n, m, k, q;
ll a[N], f[N], l[N], r[N];
char s[N];
struct node {
int l, r;
ll sum, add;
}tr[4 * N];
void pushup(int u)
{
tr[u].sum = tr[u << 1].sum + tr[u << 1 | 1].sum;
}
void build(int u, int l, int r)
{
if (l == r) tr[u] = { l, r, a[l], 0 };
else
{
tr[u] = { l, r };
int mid = l + r >> 1;
build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
pushup(u);
}
}
void modify(int u, int ql, int qr, ll val)
{
if (tr[u].l >= ql && tr[u].r <= qr) tr[u].sum = val;
else
{
int mid = tr[u].l + tr[u].r >> 1;
if (ql <= mid) modify(u << 1, ql, qr, val);
if (qr > mid) modify(u << 1 | 1, ql, qr, val);
pushup(u);
}
}
ll query(int u, int l, int r)
{
if (tr[u].l >= l && tr[u].r <= r) return tr[u].sum;
int mid = tr[u].l + tr[u].r >> 1;
ll sum = 0;
if (l <= mid) sum += query(u << 1, l, r);
if (r > mid) sum += query(u << 1 | 1, l, r);
return sum;
}
ll F(ll x)
{
ll on = abs(x * x * x - 3 * x);
ll de = 3 * x * x + 1;
return on / de * 2;
//return max(0ll, 2 * ((x + 2) / 3 - 1));
}
void del(int x)
{
l[r[x]] = l[x];
r[l[x]] = r[x];
}
void solve()
{
//rep(i, 1, 24) cout << i << " : " << F(i) << '\n';
//rep(i, 1, 10000) if(F(i) != 2 * ((i + 2) / 3 - 1)) no
cin >> n >> m;
rep(i, 1, n) l[i] = i - 1, r[i] = i + 1;
rep(i, 1, n) sci(a[i]);
build(1, 1, n);
//cout<<F(1)<<'\n';
set<int> cl;
while(m--)
{
int op, x, y;
cin >> op >> x >> y;
if(op == 1)
{
int sta = (a[x] == 0 ? r[a[x]] : x);
while(sta <= y)
{
ll to = F(a[sta]), ne = r[sta];
a[sta] = to; //modify(1, sta, sta, to);
//pll(sta)
cl.insert(sta);
if(to == 0) del(sta), modify(1, sta, sta, to);
sta = ne;
}
}
else
{
for(auto i : cl)
{
modify(1, i, i, a[i]), cl.erase(i);
}
cout << query(1, x, y) << '\n';
//del.clear();
}
}
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int T; T = 1;
//cin >> T;
while (T--)
{
solve();
}
return 0;
}