Last active
March 13, 2020 16:45
-
-
Save tony9402/0278c48ef685ef8feb3b0dbd557f4628 to your computer and use it in GitHub Desktop.
Codeforces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
#define endl "\n"; | |
using namespace std; | |
typedef long long ll; | |
int main() { | |
ios::sync_with_stdio(false); | |
cin.tie(0); | |
int t; | |
cin >> t; | |
for (; t--;) { | |
int n; | |
cin >> n; | |
vector<int> vc; | |
vector<pair<int, int>> arr; | |
for (int i = 0; i < n; i++) { | |
int x; | |
cin >> x; | |
vc.push_back(x); | |
arr.push_back(make_pair(x, i)); | |
} | |
sort(arr.begin(), arr.end()); | |
bool found = false; | |
for (int i = 0; i < vc.size(); i++) { | |
int idx = lower_bound(arr.begin(), arr.end(), make_pair(vc[i], 0)) - arr.begin(); | |
int idx2 = upper_bound(arr.begin(), arr.end(), make_pair(vc[i], 5001)) - arr.begin(); | |
if (arr[idx].first == vc[i]) { | |
if (arr[idx2 - 1].second != i) { | |
if (abs(i - arr[idx2- 1].second) > 1) { | |
found = true; | |
cout << "YES" << endl; | |
break; | |
} | |
} | |
} | |
} | |
if (!found)cout << "NO" << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment