Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Abhay Singh Bhadoria ( _Asb_ ) //
- #include<bits/stdc++.h>
- using namespace std;
- const int inf = 2147483647;
- const int M = 1e9 + 7;
- const int N = 1e5 + 5;
- int bit[N][10];
- void update(int x,int n,int val,int d){
- while(x<=n){
- bit[x][d]+=val;
- x+=x&(-x);
- }
- }
- int query(int x,int n,int d){
- int res(0);
- while(x>0){
- res+=bit[x][d];
- x-=x&(-x);
- }
- return res;
- }
- int main(){
- int n,m;
- scanf("%d%d",&n,&m);
- for(int i=1;i<=n;++i){
- int x;
- scanf("%d",&x);
- while(x>0){
- update(i,n,1,x%10);
- x/=10;
- }
- }
- while(m--){
- int l,r,res(0);
- scanf("%d%d",&l,&r);
- for(int i=0;i<10;++i){
- if(query(r,n,i)-query(l-1,n,i)>0)res++;
- }
- printf("%d\n",res);
- }
- }
Add Comment
Please, Sign In to add comment