# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1072119 | vjudge1 | Alternating Heights (CCO22_day1problem1) | C++14 | 378 ms | 14164 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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 3000;
int N, K, Q;
int A[MAXN+10], ans[MAXN+10];
int vis[MAXN+10];
vector<int> adj[MAXN+10];
bool dfs(int now)
{
vis[now]=1;
bool ret=false;
for(auto nxt : adj[now])
{
if(vis[nxt]==1) return true;
if(vis[nxt]==0) ret|=dfs(nxt);
}
vis[now]=2;
return ret;
}
bool f(int l, int r)
{
for(int i=l; i<r; i++)
{
if(i%2==l%2) adj[A[i+1]].push_back(A[i]);
else adj[A[i]].push_back(A[i+1]);
}
bool ret=false;
for(int i=1; i<=K; i++) if(!vis[i]) ret|=dfs(i);
for(int i=1; i<=K; i++)
{
adj[i].clear(), adj[i].shrink_to_fit();
vis[i]=0;
}
return !ret;
}
int main()
{
scanf("%d%d%d", &N, &K, &Q);
for(int i=1; i<=N; i++) scanf("%d", &A[i]);
for(int i=N; i>=1; i--)
{
int pos=N;
if(i+2<=N) pos=ans[i+2];
for(; pos>=i && !f(i, pos); pos--) ;
ans[i]=pos;
}
while(Q--)
{
int x, y;
scanf("%d%d", &x, &y);
if(ans[x]>=y) printf("YES\n");
else printf("NO\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... |