This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma optimize("Ofast")
//#pragma optimize("unroll-loops")
//#pragma traget("avx,avx2")
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstdint>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <random>
#include <deque>
#include <functional>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <complex>
#include <numeric>
#include <cassert>
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <thread>
typedef int ll;
typedef unsigned long long ull;
typedef long double ld;
#define el '\n'
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define point pair <ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
#include <random>
mt19937 rnd(time(0));
const ll INF = 2e18 + 10;
const ll inf = 1e9 + 10;
const ll N = 3e3 + 10;
const ll mod = 1e9 + 7;
const ll LOG = 20;
vector <ll> gr[N];
ll used[N];
bool dfs(ll v) {
used[v] = 1;
for (ll to : gr[v]) {
if (used[to] == 2)
continue;
if (used[to] == 0) {
if (dfs(to))
return 1;
} else
return 1;
}
used[v] = 2;
return 0;
}
void solve() {
ll n, k, q;
cin >> n >> k >> q;
vector <ll> a(n);
for (ll i = 0; i < n; i++)
cin >> a[i];
ll R[n];
for (ll i = 0; i < n; i++) {
ll l = i, r = n;
while (l + 1 < r) {
ll mid = (l + r) >> 1;
for (ll j = 1; j <= k; j++)
gr[j].clear(), used[j] = 0;
for (ll j = i + 1; j <= mid; j++) {
if (i % 2 != j % 2)
gr[a[j - 1]].pb(a[j]);
else
gr[a[j]].pb(a[j - 1]);
}
bool bad = 0;
for (ll j = 1; j <= k; j++)
if (used[j] == 0)
bad |= dfs(j);
if (bad) r = mid;
else l = mid;
}
R[i] = l;
}
while (q--) {
ll x, y;
cin >> x >> y;
x--, y--;
cout << (R[x] >= y ? "YES" : "NO") << el;
}
return;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen("deleg.in", "r", stdin);
//freopen("deleg.out", "w", stdout);
int tests = 1;
//cin >> tests;
while (tests--)
solve();
return 0;
}
/*
*/
Compilation message (stderr)
Main.cpp:56:21: warning: overflow in conversion from 'double' to 'll' {aka 'int'} changes value from '2.0e+18' to '2147483647' [-Woverflow]
56 | const ll INF = 2e18 + 10;
| ~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |