# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
936250 | sleepntsheep | Alternating Heights (CCO22_day1problem1) | C++17 | 475 ms | 14136 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) begin(x), end(x)
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
#define N 3005
int n, k, q, a[N], L[N];
basic_string<int> g[N];
int vs[N];
int cyclic(int u)
{
vs[u] = 1;
for (int v : g[u])
if (vs[v] == 1 || !vs[v] && cyclic(v)) return 1;
vs[u] = 2;
return 0;
}
int main()
{
ShinLena;
cin >> n >> k >> q;
for (int i = 1; i <= n; ++i)
{
cin >> a[i];
int l = 1, r = i; L[i] = i;
while (l <= r)
{
memset(vs, 0, sizeof vs);
for(int j = 1; j <= k; ++j) g[j].clear();
int m = l+r>>1, ok = 1;
for (int j = i; j > m; --j)
if(j&1) g[a[j]].push_back(a[j-1]);
else g[a[j-1]].push_back(a[j]);
for (int j = i; ok && j > m; --j) if (!vs[a[j]] && cyclic(a[j])) ok = 0;
if (ok) r = m - 1, L[i] = m;
else l = m + 1;
}
}
for (int x, y; q--;)
{
cin >> x >> y;
if (x >= L[y]) cout << "YES\n";
else cout << "NO\n";
}
return 0;
}
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... |