#include <bits/stdc++.h>
#define TASK "E"
#define int long long
#define pb push_back
#define FOR(i,a,b) for (int i = a, _b = b; i <= _b; ++i)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
const int MAXN = 3005;
int N, K, Q;
int a[MAXN], ok[MAXN];
vector<int> G[MAXN];
int deg[MAXN];
bool has_cycle() {
queue<int> q;
int cnt = 0;
vector<int> tmp_deg(K + 1);
FOR(i,1,K) tmp_deg[i] = deg[i];
FOR(i,1,K) if (tmp_deg[i] == 0) q.push(i);
while (!q.empty()) {
int u = q.front(); q.pop();
++cnt;
for (int v : G[u]) {
if (--tmp_deg[v] == 0)
q.push(v);
}
}
return cnt < K;
}
void preprocess() {
int x = 1, y = 1;
int turn = 1;
while (x <= N) {
while (y < N) {
int u = a[y], v = a[y + 1];
if (u == v) break;
if (turn & 1) G[v].pb(u), deg[u]++;
else G[u].pb(v), deg[v]++;
if (has_cycle()) {
// remove last added
if (turn & 1) G[v].pop_back(), deg[u]--;
else G[u].pop_back(), deg[v]--;
break;
}
y++;
turn ^= 1;
}
ok[x] = y;
if (x < y) {
int u = a[x], v = a[x + 1];
if (turn & 1) {
auto &vec = G[u];
vec.pop_back();
deg[v]--;
} else {
auto &vec = G[v];
vec.pop_back();
deg[u]--;
}
turn ^= 1;
} else {
y = x + 1;
turn = 1;
}
x++;
}
}
int32_t main() {
if (fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
FAST;
cin >> N >> K >> Q;
FOR(i, 1, N) cin >> a[i];
preprocess();
while (Q--) {
int x, y; cin >> x >> y;
cout << (ok[x] >= y ? "YES" : "NO") << '\n';
}
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int32_t main()':
Main.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | freopen(TASK".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | freopen(TASK".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |