https://ac.nowcoder.com/acm/contest/78292/F
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;
typedef vector<long long> VI;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define pb(i) push_back(i)
#define int long long
#define INF 0x3f3f3f3f
#define oz 998244353
#define endl '\n'
#define N 200010
const int mod = 1e9 + 7;
int p[N], si[N];
int find(int x) {
if (x != p[x]) p[x] = find(p[x]);
return p[x];
}
//size[find(b)] += size[find(a)];
//p[find(a)] = find(b);
//无论多长的回文串,一定包含 1 2 1 或 1 1 1
//则只要 la[i] = i - 2则一定存在回文串
void solve() {
int n, q;
cin >> n >> q;
VI a(n + 1);
rep(i, 1, n)cin >> a[i];
VI la(n + 1); // la[i]表示上一次出现a[i]的位置;
map<int, int> mp;
rep(i, 1, n) {
la[i] = mp[a[i]];
mp[a[i]] = i;
}
per(i, n, 1) {
if (la[i] == i - 1) {
la[i] = la[la[i]];
}
}
VI maxla(n); //维护区间最大值 因为l之前不可能有比l大的数 所以maxla[r] >= l 则该数一定出现在 l 到 r之间
rep(i, 1, n) {
maxla[i] = max(maxla[i - 1], la[i]);
}
while (q --) {
int l, r;
cin >> l >> r;
if (maxla[r] >= l)cout << "YES" << endl;
else cout << "NO" << endl;
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
// cin >> T;
while (T --)
solve();
return 0;
}