Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma comment(linker, "/STACK:65777216")
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- #include <ctime>
- #include <cstdio>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <set>
- #include <stack>
- #include <map>
- #include <queue>
- #include <string>
- #include <memory.h>
- #include <iterator>
- #define y1 trololoy1
- #define y0 trololoy0
- #define mem(A,X) memset(A,X,sizeof(A))
- #define memo(A) memset(A,0,sizeof(A))
- #define forn(I,B) for (int I=1;I<=(B);I++)
- #define forg(H,V) for (int H=first[V];h;h=next[H])
- #define rep(I,B) for (int I=0;I<(B);I++)
- #define labs(X) (((X)>0)?(X):(-(X)))
- #define ropen(X) freopen(X,"r",stdin)
- #define wopen(X) freopen(X,"w",stdout)
- #define rwopen(X) freopen(X".in","r",stdin);freopen(X".out","w",stdout)
- #define pb push_back
- #define mp make_pair
- #define all(X) (X).begin(),(X).end()
- #define sqr(X) ((X)*(X))
- using namespace std;
- typedef pair <int,int> pii;
- typedef double ld;
- typedef long long ll;
- typedef pair <ll,ll> pll;
- typedef vector<int> vi;
- const int N=255555;
- const int INF=111111111;
- const double eps=1e-9;
- const double pi=3.14159265358979;
- struct tree{
- int c[10],l,r,p;
- } t[N+N+N];
- int n,m,old[10],q;
- char s[N];
- inline void push(int v){
- t[v].p%=10;
- if (!t[v].p) return;
- rep(i,10) old[i]=t[v].c[i];
- rep(i,10) t[v].c[i]=old[(i-t[v].p+10)%10];
- t[v+v].p+=t[v].p;t[v+v+1].p+=t[v].p;
- t[v].p=0;
- }
- void build(int v,int l,int r){
- t[v].l=l;t[v].r=r;t[v].p=0;
- if (l==r) t[v].c[s[l-1]-'0']=1;
- else{
- build(v+v,l,(l+r)/2);
- build(v+v+1,(l+r)/2+1,r);
- rep(i,10) t[v].c[i]=t[v+v].c[i]+t[v+v+1].c[i];
- }
- }
- int get_sum(int v,int l,int r){
- if (t[v].l>r || t[v].r<l) return 0;
- push(v);
- if (t[v].l>=l && t[v].r<=r){
- q=0;
- rep(i,10) q+=t[v].c[i]*i;
- return q;
- }
- return get_sum(v+v,l,r)+get_sum(v+v+1,l,r);
- }
- void upd(int v,int l,int r){
- if (t[v].l>r || t[v].r<l) return;
- if (t[v].l>=l && t[v].r<=r){
- ++t[v].p;
- return;
- }
- push(v);
- upd(v+v,l,r);
- upd(v+v+1,l,r);
- rep(i,10) t[v].c[i]=t[v+v].c[i]+t[v+v+1].c[i];
- }
- int main(){
- ropen("input.txt");
- wopen("output.txt");
- scanf("%d%d\n",&n,&m);
- gets(s);
- build(1,1,n);
- forn(i,m){
- int a,b;
- scanf("%d%d",&a,&b);
- printf("%d\n",get_sum(1,a,b));
- upd(1,a,b);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment