#include<bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,l,r) for(int i=(l);i>=(r);i--)
#define ll long long
#define pii pair<int, int>
#define mset(s,t) memset(s,t,sizeof(t))
#define mcpy(s,t) memcpy(s,t,sizeof(t))
#define fir first
#define pb push_back
#define sec second
#define sortall(x) sort((x).begin(),(x).end())
inline int read () {
int x = 0, f = 0;
char ch = getchar();
while (!isdigit(ch)) f |= (ch=='-'),ch= getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return f?-x:x;
}
template<typename T> void print(T x) {
if (x < 0) putchar('-'), x = -x;
if (x >= 10) print(x/10);
putchar(x % 10 + '0');
}
const int N = 4e5 + 10;
const int mod = 1e9 + 7;
string s;
struct bigtree {
int l, r, ma;
}bt[N];
int n, q;
ll qmi (ll a, ll b) {
ll ans = 1;
while(b) {
if (b & 1) ans =ans * a %mod;
a = a * a %mod;
b >>= 1;
}
return ans;
}
void buildBT (int p, int l, int r) {
bt[p].l = l, bt[p].r = r;
if (l == r) {
bt[p].ma = s[l - 1] - '0';
return;
}
int mid = l + r>> 1;
buildBT (p * 2, l, mid);
buildBT (p * 2 + 1, mid+ 1, r);
bt[p].ma = max (bt[p * 2].ma, bt[p * 2 + 1].ma);
}
int askma (int p, int l, int r) {
int res = 0;
if (bt[p].l >= l && bt[p].r <= r) {
return bt[p].ma;
}
int mid = bt[p].l + bt[p].r >> 1;
if (mid >= l)
res = max (res, askma(p* 2, l, r));
if (mid + 1 <= r)
res = max (res, askma(p * 2 + 1, l, r));
return res;
}
void changeBT (int p, int id, int x) {
if (bt[p].l == id && bt[p].r == id) {
bt[p].ma = x;
return;
}
int mid = bt[p].l + bt[p].r >> 1;
if (mid >= id) changeBT(p * 2, id, x);
if (mid + 1 <= id) changeBT(p * 2 + 1, id, x);
bt[p].ma = max (bt[p * 2].ma, bt[p * 2 + 1].ma);
}
struct jztree {
int l, r;
ll res;
}t[N][11];
void buildJZ (int p, int l, int r, int x) {
t[p][x].l = l, t[p][x].r = r;
if (l == r) {
t[p][x].res = s[l - 1] - '0';
return;
}
int mid = l + r>> 1;
buildJZ(p * 2, l, mid, x);
buildJZ(p * 2 + 1, mid + 1, r, x);
int len = t[p * 2 + 1][x].r - t[p * 2 + 1][x].l + 1;
t[p][x].res = (qmi(x, len) * t[p * 2][x].res %mod + t[p * 2 + 1][x].res) %mod;
}
ll askans (int p, int l, int r, int x) {
int res1 = 0, res2 = 0;
if (t[p][x].l >= l && t[p][x].r <= r) {
return t[p][x].res %mod;
}
int mid = t[p][x].l + t[p][x].r >> 1;
if (mid >= l) {
res1 = askans(p * 2, l , r, x);
}
if (mid + 1 <= r)
{
res2 = askans(p * 2 + 1, l, r, x);
int len = min (r, t[p * 2 + 1][x].r) - mid;
return (res1 * qmi(x, len) %mod + res2) % mod;
}
else return res1 %mod;
}
void addans (int p, int id, int k, int x) {
if (t[p][x].l == id && t[p][x].r == id) {
t[p][x].res = k;
return;
}
int mid = t[p][x].l + t[p][x].r >> 1;
if (mid >= id)
addans(p * 2, id, k, x);
if (mid + 1 <= id)
addans (p * 2 + 1, id, k, x);
int len = t[p *2 + 1][x].r - t[p * 2 + 1][x].l + 1;
t[p][x].res = (qmi(x, len) * t[p * 2][x].res + t[p * 2 + 1][x].res) %mod;
}
void solve(){
cin >> n >> q;
cin >> s;
buildBT (1, 1, n);
for (int i =2; i<= 10; i++)
buildJZ(1, 1, n, i);
while(q --) {
int op;
cin >> op;
int x, y;
cin >> x >> y;
if (op == 1) {
changeBT (1, x, y);
for (int i =2; i<= 10; i++)
addans(1, x, y, i);
}
else {
int ma = askma(1, x, y) + 1;
if (ma == 1) ma ++;
cout << askans(1, x, y, ma) << endl;
}
}
}
int main () {
int t;
t = 1;
while (t --) solve();
return 0;
}
细化问题 要不要对一个数字进行讨论,对于不同的进制,这是不需要的因为我们先查询最大的数字ma然后ma++,这就是表示进制数 抓住主要问题,这一题主要在于合并区间,左边*len + 右边然后建立线段树就行 所能表示的进制最小值,就是取最大的数加1表示的进制否则后面将会更大可以化开看