Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. const int MAX_N = 500005;
  5. const int CYF = 5;
  6.  
  7. int A[MAX_N];
  8. int P[CYF + 1][MAX_N];
  9.  
  10. bool czy(int x, int y, int cyfra) {
  11.     return (P[cyfra][y] - P[cyfra][x - 1] > 0);
  12. }
  13.  
  14. int main() {
  15.     int n, m;
  16.     cin >> n >> m;
  17.     for(int i = 1; i <= n; i++)
  18.         cin >> A[i];
  19.  
  20.     for(int cyfra = 1; cyfra <= CYF; cyfra++) {
  21.         P[cyfra][0] = 0;
  22.         for(int i = 1; i <= n; i++) {
  23.             P[cyfra][i] = P[cyfra][i - 1];
  24.             if(A[i] == cyfra) P[cyfra][i]++;
  25.         }
  26.     }
  27.    
  28.     while(m--) {
  29.         int a, b;
  30.         cin >> a >> b;
  31.         for(int cyfra = 1; cyfra <= CYF; cyfra++) {
  32.             if(czy(a, b, cyfra)) {
  33.                 cout << cyfra << endl;
  34.                 break;
  35.             }
  36.         }
  37.     }
  38.    
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement