//#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
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;
| ~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
126 ms |
12848 KB |
Output is correct |
2 |
Correct |
170 ms |
12868 KB |
Output is correct |
3 |
Correct |
144 ms |
12880 KB |
Output is correct |
4 |
Correct |
94 ms |
7404 KB |
Output is correct |
5 |
Correct |
103 ms |
9316 KB |
Output is correct |
6 |
Correct |
159 ms |
12748 KB |
Output is correct |
7 |
Correct |
128 ms |
12880 KB |
Output is correct |
8 |
Correct |
129 ms |
12880 KB |
Output is correct |
9 |
Correct |
134 ms |
12960 KB |
Output is correct |
10 |
Correct |
149 ms |
13372 KB |
Output is correct |
11 |
Correct |
200 ms |
13924 KB |
Output is correct |
12 |
Correct |
187 ms |
13136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
109 ms |
11112 KB |
Output is correct |
2 |
Correct |
110 ms |
11092 KB |
Output is correct |
3 |
Correct |
113 ms |
11052 KB |
Output is correct |
4 |
Correct |
93 ms |
8264 KB |
Output is correct |
5 |
Correct |
103 ms |
9400 KB |
Output is correct |
6 |
Correct |
108 ms |
11088 KB |
Output is correct |
7 |
Correct |
112 ms |
11088 KB |
Output is correct |
8 |
Correct |
110 ms |
11024 KB |
Output is correct |
9 |
Correct |
109 ms |
11344 KB |
Output is correct |
10 |
Correct |
111 ms |
12112 KB |
Output is correct |
11 |
Correct |
116 ms |
12116 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
426 ms |
604 KB |
Output is correct |
3 |
Correct |
451 ms |
628 KB |
Output is correct |
4 |
Correct |
10 ms |
584 KB |
Output is correct |
5 |
Correct |
0 ms |
392 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
285 ms |
624 KB |
Output is correct |
8 |
Correct |
482 ms |
604 KB |
Output is correct |
9 |
Correct |
543 ms |
604 KB |
Output is correct |
10 |
Correct |
439 ms |
612 KB |
Output is correct |
11 |
Correct |
604 ms |
604 KB |
Output is correct |
12 |
Correct |
369 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
126 ms |
12848 KB |
Output is correct |
2 |
Correct |
170 ms |
12868 KB |
Output is correct |
3 |
Correct |
144 ms |
12880 KB |
Output is correct |
4 |
Correct |
94 ms |
7404 KB |
Output is correct |
5 |
Correct |
103 ms |
9316 KB |
Output is correct |
6 |
Correct |
159 ms |
12748 KB |
Output is correct |
7 |
Correct |
128 ms |
12880 KB |
Output is correct |
8 |
Correct |
129 ms |
12880 KB |
Output is correct |
9 |
Correct |
134 ms |
12960 KB |
Output is correct |
10 |
Correct |
149 ms |
13372 KB |
Output is correct |
11 |
Correct |
200 ms |
13924 KB |
Output is correct |
12 |
Correct |
187 ms |
13136 KB |
Output is correct |
13 |
Correct |
109 ms |
11112 KB |
Output is correct |
14 |
Correct |
110 ms |
11092 KB |
Output is correct |
15 |
Correct |
113 ms |
11052 KB |
Output is correct |
16 |
Correct |
93 ms |
8264 KB |
Output is correct |
17 |
Correct |
103 ms |
9400 KB |
Output is correct |
18 |
Correct |
108 ms |
11088 KB |
Output is correct |
19 |
Correct |
112 ms |
11088 KB |
Output is correct |
20 |
Correct |
110 ms |
11024 KB |
Output is correct |
21 |
Correct |
109 ms |
11344 KB |
Output is correct |
22 |
Correct |
111 ms |
12112 KB |
Output is correct |
23 |
Correct |
116 ms |
12116 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
426 ms |
604 KB |
Output is correct |
27 |
Correct |
451 ms |
628 KB |
Output is correct |
28 |
Correct |
10 ms |
584 KB |
Output is correct |
29 |
Correct |
0 ms |
392 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
285 ms |
624 KB |
Output is correct |
32 |
Correct |
482 ms |
604 KB |
Output is correct |
33 |
Correct |
543 ms |
604 KB |
Output is correct |
34 |
Correct |
439 ms |
612 KB |
Output is correct |
35 |
Correct |
604 ms |
604 KB |
Output is correct |
36 |
Correct |
369 ms |
600 KB |
Output is correct |
37 |
Correct |
593 ms |
13436 KB |
Output is correct |
38 |
Correct |
565 ms |
13196 KB |
Output is correct |
39 |
Correct |
133 ms |
12884 KB |
Output is correct |
40 |
Correct |
93 ms |
8276 KB |
Output is correct |
41 |
Correct |
103 ms |
9812 KB |
Output is correct |
42 |
Correct |
509 ms |
13392 KB |
Output is correct |
43 |
Correct |
550 ms |
13688 KB |
Output is correct |
44 |
Correct |
280 ms |
13392 KB |
Output is correct |
45 |
Correct |
697 ms |
13952 KB |
Output is correct |
46 |
Correct |
602 ms |
13908 KB |
Output is correct |
47 |
Correct |
714 ms |
13972 KB |
Output is correct |