Advertisement
Guest User

H

a guest
Oct 18th, 2012
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define MAXN 10005
  4. #define MAXC 256
  5. int n;
  6. int c[MAXN];
  7. int s[MAXC][MAXN];
  8.  
  9. int main()
  10. {
  11.     freopen( "input.txt", "rt", stdin );
  12.     freopen( "output.txt", "wt", stdout );
  13.  
  14.     int k;
  15.     scanf( "%d %d", &n, &k );
  16.  
  17.     int minc = 256, maxc = 0;
  18.  
  19.     for( int i = 0; i < n; ++ i )
  20.     {
  21.         scanf( "%d", &c[i] );
  22.         if( c[i] < minc )
  23.             minc = c[i];
  24.         if( c[i] > maxc )
  25.             maxc = c[i];
  26.     }
  27.  
  28.     for( int z = minc; z <=maxc; ++ z )
  29.     {
  30.         int sum = 0;
  31.         for( int i = 0; i < n; ++ i )
  32.         {
  33.             if( c[i] == z )
  34.                 ++sum;
  35.             s[z][i] = sum;
  36.         }
  37.     }
  38.  
  39.     for( int q = 0; q < k; ++ q )
  40.     {
  41.         int l, r;
  42.         scanf( "%d %d", &l, &r );
  43.         --l; --r;
  44.  
  45.         int cnt = 0;
  46.         for( int z = minc; z <= maxc; ++ z )
  47.         {
  48.             int sum = s[z][r];
  49.             if( l > 0 )
  50.                 sum -= s[z][l-1];
  51.  
  52.             if( sum > 0 )
  53.                 ++cnt;
  54.         }
  55.         printf( "%d\n", cnt );
  56.     }
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement