Skip to content

Instantly share code, notes, and snippets.

@nomarlo
Created July 24, 2016 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nomarlo/d79cf9fe600a32003c8f7c80e0d081c1 to your computer and use it in GitHub Desktop.
Save nomarlo/d79cf9fe600a32003c8f7c80e0d081c1 to your computer and use it in GitHub Desktop.
/**
La idea en este problema es llevar un acumulado pero de los numeros que hay (del 0 al 9) hasta x posición
**/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <sstream>
#include <map>
#include <cstdio>
#include <queue>
#include <string>
#include <iomanip>
#define gc getchar_unlocked
using namespace std;
typedef vector<int> vi;
int n,q,l,r;
int N[100005][10];
/**solo es para leer más rapido, se puede usar scanf en su lugar**/
void scanint(int &x)
{
register int c = gc();
x = 0;
int neg = 0;
for(;((c<48 || c>57) && c != '-');c = gc());
if(c=='-') {neg=1;c=gc();}
for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
if(neg) x=-x;
}
int aux;
int main(){
while(scanf("%d",&n)!=EOF){
for(int i=1;i<=n;i++){
scanint(aux);
for(int e=0;e<10;e++)
N[i][e]=N[i-1][e];
N[i][aux]++;
}
scanint(q);
while(q--){
scanf("%d %d",&l,&r);
if(l==r){
printf("1\n");
continue;
}
l--;
int res=0;
for(int i=0;i<10;i++){
res+=((N[r][i]-N[l][i])>=1?1:0);
}
printf("%d\n",res);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment