This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> Data;
int arr[100000];
ll m = 1000000007;
Data init(int ind){
Data ans = vector<vector<ll>>(4,vector<ll>(4,0));
for (int x = 0; x<4; x++){
bool isEq = x/2;
bool was1 = x%2;
for (int i = 0; i<=(isEq?arr[ind]:9); i++){
if (was1 && i==3){continue;}
ans[x][(i==arr[ind]&&isEq)*2+(i==1)]++;
}
}
return ans;
}
Data combine(const Data &a, const Data &b){
Data ans = vector<vector<ll>>(4,vector<ll>(4,0));
for (int r = 0; r<4; r++){
for (int c = 0; c<4; c++){
ans[r][c]+=a[r][0]*b[0][c];ans[r][c]%=m;
ans[r][c]+=a[r][1]*b[1][c];ans[r][c]%=m;
ans[r][c]+=a[r][2]*b[2][c];ans[r][c]%=m;
ans[r][c]+=a[r][3]*b[3][c];ans[r][c]%=m;
}
}
return ans;
}
struct Node{
int s,e,m;
Data v;
Node *l, *r;
Node(int _s, int _e){
s=_s;e=_e;
m=(s+e)/2;
if (s==e){
v = init(s);
return;
}
l = new Node(s,m);
r = new Node(m+1,e);
v = combine(l->v, r->v);
}
void update(int ind, int val){
if (s==e){
arr[ind]=val;
v = init(ind);
return;
}
if (ind<=m){
l->update(ind, val);
} else {
r->update(ind, val);
}
v = combine(l->v, r->v);
}
Data query(int a, int b){
if (s==a&&e==b){
return v;
}
if (b<=m){
return l->query(a,b);
} else if (m<a){
return r->query(a,b);
} else {
return combine(l->query(a,m),r->query(m+1,b));
}
}
};
Node *root;
ll ans(int a, int b){
Data ad = root->query(a,b);
return (ad[2][0]+ad[2][1]+ad[2][2]+ad[2][3])%m;
}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
int n,q;
cin>>n>>q;
string s;
cin>>s;
for (int i = 0; i<n; i++){
arr[i]=s[i]-'0';
}
root = new Node(0,n-1);
cout<<ans(0,n-1)<<'\n';
for (int i = 0; i<q; i++){
int t;
cin>>t;
if (t==1){
int a,b;
cin>>a>>b;
a--;b--;
cout<<ans(a,b)<<'\n';
} else {
int ind,val;
cin>>ind>>val;
ind--;
root->update(ind,val);
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |