//雪花飄飄北風嘯嘯
//天地一片蒼茫
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}
#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int MOD=1000000007;
int n,q;
int arr[100005];
ii memo[100005][2];
ii operator+(ii i, ii j){
return ii((i.fi+j.fi)%MOD,(i.se+j.se)%MOD);
}
ii dp(int i,int flag){ //prev is 1, flag=1, else flag=0
if (i==0){
if (flag==1) return ii(0,1);
else return ii(1,0);
}
if (memo[i][flag]!=ii(-1,-1)) return memo[i][flag];
ii ans=ii(0,0);
rep(x,0,10){
if (flag && x==3) continue;
ans=ans+dp(i-1,x==1);
}
return memo[i][flag]=ans;
}
struct dat{
int l,r;
bool bad;
ll ans0,ans1;
int len;
};
dat operator+(dat i,dat j){
dat res;
res.l=i.l,res.r=j.r;
res.len=i.len+j.len;
res.bad=i.bad||j.bad||(i.r==1 && j.l==3);
if (i.bad){
res.ans0=i.ans0;
res.ans1=j.ans0;
}
else{
res.ans0=j.ans0;
res.ans1=j.ans1;
auto temp=dp(j.len,0);
res.ans0=(res.ans0+temp.fi*i.ans0)%MOD;
res.ans1=(res.ans1+temp.se*i.ans0)%MOD;
temp=dp(j.len,1);
res.ans0=(res.ans0+temp.fi*i.ans1)%MOD;
res.ans1=(res.ans1+temp.se*i.ans1)%MOD;
}
return res;
}
struct node{
int s,e,m;
dat val;
node *l,*r;
node (int _s,int _e){
s=_s,e=_e,m=s+e>>1;
if (s!=e){
l=new node(s,m);
r=new node(m+1,e);
}
}
void update(int i,int k){
if (s==e){
val.l=val.r=k;
if (k<=1) val.ans0=k,val.ans1=0;
else val.ans0=k-1,val.ans1=1;
val.bad=false;
val.len=1;
}
else{
if (i<=m) l->update(i,k);
else r->update(i,k);
val=l->val+r->val;
}
}
dat query(int i,int j){
if (s==i && e==j) return val;
else if (j<=m) return l->query(i,j);
else if (m<i) return r->query(i,j);
else return l->query(i,m)+r->query(m+1,j);
}
} *root=new node(0,100005);
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
memset(memo,-1,sizeof(memo));
cin>>n>>q;
string s;
cin>>s;
rep(x,0,n) root->update(x,s[x]-'0');
auto temp=root->query(0,n-1);
cout<<(temp.ans0+temp.ans1+(!temp.bad))%MOD<<endl;
int a,b;
while (q--){
cin>>a;
if (a==2){
cin>>a>>b;
root->update(a-1,b);
}
else{
cin>>a>>b;
auto temp=root->query(a-1,b-1);
cout<<(temp.ans0+temp.ans1+(!temp.bad))%MOD<<endl;
}
}
}
Compilation message
lucky.cpp: In constructor 'node::node(int, int)':
lucky.cpp:101:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
s=_s,e=_e,m=s+e>>1;
~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
19072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
19072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
26 ms |
19456 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
26 ms |
19456 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
19072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
19072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |