Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- const int MAX_N = 500005;
- const int CYF = 5;
- int A[MAX_N];
- int P[CYF + 1][MAX_N];
- bool czy(int x, int y, int cyfra) {
- return (P[cyfra][y] - P[cyfra][x - 1] > 0);
- }
- int main() {
- int n, m;
- cin >> n >> m;
- for(int i = 1; i <= n; i++)
- cin >> A[i];
- for(int cyfra = 1; cyfra <= CYF; cyfra++) {
- P[cyfra][0] = 0;
- for(int i = 1; i <= n; i++) {
- P[cyfra][i] = P[cyfra][i - 1];
- if(A[i] == cyfra) P[cyfra][i]++;
- }
- }
- while(m--) {
- int a, b;
- cin >> a >> b;
- for(int cyfra = 1; cyfra <= CYF; cyfra++) {
- if(czy(a, b, cyfra)) {
- cout << cyfra << endl;
- break;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement