1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| #include <bits/stdc++.h> using namespace std;
constexpr int d[9][6] = { {1, 2, 4, 3, 5, 6}, {1, 2, 5, 3, 4, 6}, {1, 2, 6, 3, 4, 5}, {1, 3, 4, 2, 5, 6}, {1, 3, 5, 2, 4, 6}, {1, 3, 6, 2, 4, 5}, {1, 4, 5, 2, 3, 6}, {1, 4, 6, 2, 3, 5}, {1, 5, 6, 2, 3, 4}};
int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int n, q; cin >> n >> q; vector<int> a(n + 1); for (int i = 1; i <= n; i++) cin >> a[i];
while (q--) { int l, r; cin >> l >> r; if (r - l + 1 >= 48) { cout << "YES" << endl; continue; } vector<int> nums; for (int i = l; i <= r; i++) { nums.push_back(a[i]); } sort(nums.begin(), nums.end());
auto check = [&](int a, int b, int c) { return a < (b + c) && b < (a + c) && c < (a + b); };
vector<int> ok; bool have = false;
for (int i = 0; i < nums.size() - 2; i++) { if (check(nums[i], nums[i + 1], nums[i + 2])) { ok.push_back(i); if (ok.back() > ok[0] + 2) { have = true; break; } } }
if (ok.empty()) { cout << "NO" << endl; continue; }
if (have) { cout << "YES" << endl; continue; }
for (int i = 0; i < nums.size() - 5; i++) { for (int j = 0; j < 9; j++) { if (check(nums[i + d[j][0] - 1], nums[i + d[j][1] - 1], nums[i + d[j][2] - 1]) && check(nums[i + d[j][3] - 1], nums[i + d[j][4] - 1], nums[i + d[j][5] - 1])) { have = true; break; } } if (have) break; }
if (have) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0; }
|