# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1124843 | VinhLuu | Alternating Heights (CCO22_day1problem1) | C++20 | 899 ms | 28060 KiB |
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
//#define int long long
#define ll long long
#define all(lpv) lpv.begin(), lpv.end()
#define fi first
#define se second
#define pot(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
using namespace std;
typedef pair<int,int> pii;
const int N = 1e6 + 5;
const int oo = 1e9;
int n, f[N], k, q, a[N];
vector<int> p[N];
int in[N];
bool ff = true;
void dfs(int u) {
in[u] = 1;
for(auto j : p[u]) {
if(in[j] == 2) continue;
if(!in[j]) {
dfs(j);
} else {
ff = false;
return;
}
if(!ff) return;
}
in[u] = 2;
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "v"
if(fopen(task ".inp","r")) {
freopen(task ".inp","r",stdin);
freopen(task ".out","w",stdout);
}
cin >> n >> k >> q;
for(int i = 1; i <= n; i ++) cin >> a[i];
for(int i = 1; i <= n; i ++) {
f[i] = i;
int l = i + 1, r = n, mid;
while(l <= r) {
mid = (l + r) / 2;
for(int j = 1; j <= k; j ++) {
p[j].clear();
in[j] = 0;
}
for(int j = i; j < mid; j ++) {
if(j % 2 == i % 2) { // >
p[a[j]].push_back(a[j + 1]);
} else {
p[a[j + 1]].push_back(a[j]);
}
}
ff = true;
for(int j = 1; j <= k; j ++) if(!in[j]) {
dfs(j);
if(!ff) break;
}
if(ff) f[i] = mid, l = mid + 1;
else r = mid - 1;
}
}
while(q--) {
int l, r; cin >> l >> r;
if(f[l] < r) cout << "NO\n";
else cout << "YES\n";
}
}
Compilation message (stderr)
# | 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... |