#include <bits/stdc++.h>
using namespace std;
#define sonic ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define IO(main) if(fopen(main".inp","r")){freopen(main".inp","r",stdin);freopen(main".out","w",stdout);}
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define ins insert
#define pb push_back
#define el cout << endl
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define MASK(i) ((1LL)<<(i))
#define BIT(x,i) (((x)>>(i))&(1LL))
#define FOR(i, a, b) for(int (i)=(a);(i)<=(b); i++)
#define FORD(i, a, b) for(int (i)=(a);(i)>=(b); i--)
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<pii>;
const int N = 1e6 + 9;
const int mod = 1e9 + 7;
const ll INF = 1e18 + 7;
const int base = 31;
const int LOG = 20;
const ll MOD = 1e9 + 7;
int mul(int x, int y) {return 1LL * x * y % mod;}
int calPw(int x, int y)
{
int ans = 1;
while(y)
{
if (y&1) ans = 1LL * ans * x % mod;
x = 1LL * x * x % mod;
y >>= 1;
}
return ans;
}
int d4x[4] = {1, 0, -1, 0};
int d4y[4] = {0, 1, 0, -1};
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
///Author: Le Chi Thien Luong The Vinh high school 2008
///code
void Solve(){
}
int n, k, q;
ll a[N], vis[N], ans[N];
vector<int>adj[N];
bool dfs(int u){
vis[u] = 1;
for(int v : adj[u]){
if(vis[v] == 0){
if(dfs(v))return true;
}
else if(vis[v] == 1)return true;
}
vis[u] = 2;
return false;
}
bool check(int l, int r){
FOR(i, 1, n){
adj[i].clear();
vis[i] = 0;
}
int ok = 1;
FOR(i, l, r - 1){
if(ok)adj[a[i]].push_back(a[i + 1]);
else adj[a[i + 1]].push_back(a[i]);
ok^=1;
}
FOR(i, 1, k){
if(vis[i] == 0 && dfs(i))return false;
}
return true;
}
void Read(){
cin >> n >> k >> q;
FOR(i, 1, n){
cin >> a[i];
}
FOR(i, 1, n){
int l = i, r = n;
while(l <= r){
int mid = l + r >> 1;
if(check(i, mid)){
l = mid + 1;
ans[i] = mid;
}
else r = mid - 1;
}
}
while(q--){
int u, v;
cin >> u >> v;
if(ans[u] >= v)cout << "YES" << endl;
else cout << "NO" << endl;
}
}
int main()
{
sonic;
int TEST = 1;
// cin >> TEST;
while(TEST--)
{
Read();
Solve();
}
}
# | 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... |