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;
int n, k, q, arr[3010], dp[3010][3010], x, y;
set<pair<int, int>> odd, even;
pair<int, int> temp;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k >> q;
for(int i=1; i<=n; i++) {
cin >> arr[i];
}
for(int i=1; i<=n; i++) {
even.clear();
odd.clear();
for(int j=i+1; j<=n; j++) {
temp = make_pair(min(arr[j-1], arr[j]), max(arr[j-1], arr[j]));
if(j%2 == 0) {
if(odd.count(temp) == 0 && arr[j-1] != arr[j]) {
dp[i][j] = 1;
if(even.count(temp) == 0) {
even.insert(temp);
}
} else {
break;
}
} else {
if(even.count(temp) == 0 && arr[j-1] != arr[j]) {
dp[i][j] = 1;
if(odd.count(temp) == 0) {
odd.insert(temp);
}
} else {
break;
}
}
}
}
while(q--) {
cin >> x >> y;
if(x == y || dp[x][y]) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
return 0;
}
# | 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... |