/*#pragma GCC optimize("O3")
#pragma GCC optimization("Ofast,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")*/
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
#define ll long long
#define ll1 long long
#define ull unsigned long long
#define dou long double
#define str string
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define vpll vector<pair<ll, ll>>
#define vbool vector<bool>
#define vstr vector<str>
#define vvll vector<vll>
#define pb push_back
#define pf push_front
#define endl "\n"
#define fr first
#define se second
// #define sortcmp(a) sort(a.begin(), a.end(), cmp)
#define sort(a) sort(a.begin(), a.end())
#define reverse(a) reverse(a.begin(), a.end())
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
//using namespace __gnu_pbds;
const ll INF = 1e18+7;
const int lg = 20;
const ll MOD = 1e9+7;
//const ll MOD2 = 998244353;
//const ll MOD3 = 1e6+3;
mt19937 rng(1488);
ll randll(ll l, ll r) {
return uniform_int_distribution<ll>(l, r)(rng);
}
vector<deque<ll>> g;
vbool us, us1;
bool q1;
void dfs(ll v) {
//cout << "! " << v << endl;
us[v] = 1;
us1[v] = 1;
for (int i : g[v]) {
//cout << i << ' ';
if (us1[i]) q1 = 1;
if (!us[i]) dfs(i);
}
//cout << endl;
us1[v] = 0;
}
bool f(ll k) {
us.clear();
us1.clear();
us.resize(k+7, 0);
us1.resize(k+7, 0);
q1 = 0;
for (int i = 1; i <= k; i ++) {
//cout << i << endl;
if (!us[i]) dfs(i);
}
return q1;
}
int main() {
speed;
ll n, k, q;
cin >> n >> k >> q;
g.resize(k+7);
vll a(n);
for (int i = 0; i < n; i ++) {
cin >> a[i];
}
vll p(n, -1);
ll l = 0;
for (int i = 0; i < n; i ++) {
/*for (int i = 1; i <= k; i ++) {
cout << i << ": ";
for (int j : g[i]) cout << j << ' ';
cout << endl;
}
cout << endl;*/
if (i != 0 && l >= i) {
if (i% 2 == 0) g[a[i]].pop_front();
else g[a[i-1]].pop_front();
}
/*for (int i = 1; i <= k; i ++) {
cout << i << ": ";
for (int j : g[i]) cout << j << ' ';
cout << endl;
}
cout<< f(k) << endl;
cout << endl;*/
while (l < n && !f(k)) {
l ++;
if (l > i) {
if (l % 2 == 1) g[a[l-1]].pb(a[l]);
else g[a[l]].pb(a[l-1]);
}
/*for (int i = 1; i <= k; i ++) {
cout << i << ": ";
for (int j : g[i]) cout << j << ' ';
cout << endl;
}
cout<< f(k) << endl;*/
}
p[i] = l;
//cout << l << endl;
}
while (q --) {
ll l, r;
cin >> l >> r;
l --, r --;
if (p[l] > r) cout << "YES" << endl;
else cout << "NO" << endl;
}
}
| # | 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... |