Submission #966149

#TimeUsernameProblemLanguageResultExecution timeMemory
966149vjudge1Alternating Heights (CCO22_day1problem1)C++17
0 / 25
260 ms38276 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...