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 int ll;
typedef double ld;
const ll mod=1e9+7;
#define endl '\n'
ll n,k,q,arr[3007],vis[3007],s[3007];
vector<vector<ll>>v(3007);
bool f=0;
void dfs(ll idx)
{
vis[idx]=1;
s[idx]=1;
for(int i=0; i<v[idx].size(); i++)
{
if(vis[v[idx][i]]&&s[v[idx][i]])
{
f=1;
break;
}
else if(vis[v[idx][i]])
continue;
dfs(v[idx][i]);
}
s[idx]=0;
}
int32_t main()
{
//freopen("jumping.in","r",stdin);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>k>>q;
for(int i=0; i<n; i++)
cin>>arr[i];
ll m[n];
for(int h=0;h<2;h++)
{
for(int i=h,r=i+1,c=0;i<n;i+=2)
{
while(r<n)
{
if(c==0)
{
c++;
v[arr[r]-1].push_back(arr[r-1]-1);
}
else
{
c=0;
v[arr[r-1]-1].push_back(arr[r]-1);
}
for(int j=0;j<k;j++)vis[j]=0;
f=0;
for(int j=0;j<k;j++)
{
if(vis[j]==0)
dfs(j);
}
if(f)break;
r++;
}
m[i]=r-1;
for(int j=0;j<k;j++)v[j].clear();
}
}
while(q--)
{
ll a,b;
cin>>a>>b;
a--,b--;
if(m[a]>=b)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void dfs(ll)':
Main.cpp:14:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for(int i=0; i<v[idx].size(); i++)
| ~^~~~~~~~~~~~~~
# | 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... |