SHARE
TWEET

Chomiki

a guest Aug 25th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2. #define N 500001
  3. int hamsters[5];
  4. int hamsters1[N];
  5. int hamsters2[N];
  6. int hamsters3[N];
  7. int hamsters4[N];
  8. int hamsters5[N];
  9. int youngest[N-1];
  10.  
  11. int main()
  12. {
  13.     int n, m, d, first, last;
  14.    
  15.     scanf("%d %d", &n, &m);
  16.     for (int i = 1; i <= n; i++) {
  17.         scanf("%d", &d);
  18.         if (d == 1)
  19.             hamsters[0]++;
  20.         else if (d == 2)
  21.             hamsters[1]++;
  22.         else if (d == 3)
  23.             hamsters[2]++;
  24.         else if (d == 4)
  25.             hamsters[3]++;
  26.         else if (d == 5)
  27.             hamsters[4]++;
  28.         hamsters1[i] = hamsters[0];
  29.         hamsters2[i] = hamsters[1];
  30.         hamsters3[i] = hamsters[2];
  31.         hamsters4[i] = hamsters[3];
  32.         hamsters5[i] = hamsters[4];
  33.     }
  34.     for (int i = 0; i < m; i++) {
  35.         scanf("%d %d", &first, &last);
  36.         if ((hamsters1[last] - hamsters1[first-1]) >= 1)
  37.             youngest[i] = 1;
  38.         else if ((hamsters2[last] - hamsters2[first-1]) >= 1)
  39.             youngest[i] = 2;
  40.         else if ((hamsters3[last] - hamsters3[first-1]) >= 1)
  41.             youngest[i] = 3;
  42.         else if ((hamsters4[last] - hamsters4[first-1]) >= 1)
  43.             youngest[i] = 4;
  44.         else if ((hamsters5[last] - hamsters5[first-1]) >= 1)
  45.             youngest[i] = 5;
  46.     }
  47.     for (int i = 0; i < m; i++)
  48.         printf("%d\n", youngest[i]);
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top