Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- using ll = long long;
- vector<ll> a, t;
- int n, q;
- int mt(int i, int j)
- {
- if (a[i] > a[j])
- return i;
- return j;
- }
- void build(int v = 1, int tl = 0, int tr = n - 1)
- {
- if (tl == tr)
- t[v] = tl;
- else
- {
- int tm = tl + tr >> 1;
- build(v*2, tl, tm);
- build(v*2 + 1, tm + 1, tr);
- t[v] = max(a[t[v*2]], a[t[v*2+1]]);
- }
- }
- ll mc(int l, int r, int v = 1, int tl = 0, int tr = n - 1)
- {
- if (l > r)
- return a.size() - 1;
- if (tl == l && tr == r)
- return t[v];
- int tm = tl + tr >> 1;
- return mt(mc(l, min(tm, r), v*2, tl, tm), mc(max(tm + 1, l), r, v*2 + 1, tm + 1, tr));
- }
- int main()
- {
- cin >> n >> q;
- a.resize(n);
- t.resize(4*n);
- for (int i = 0; i < n; ++i)
- cin >> a[i];
- a.push_back((ll)-1);
- build();
- while (q--)
- {
- int l, r;
- cin >> l >> r;
- bool ws = 0;
- for (int i = l - 1; i < r; ++i)
- {
- ll x, y;
- x = mc(i + 1, r-1);
- y = mt(mc(i + 1, x - 1), mc(x + 1, r-1));
- if (a[x] >= a[y] && a[x] >= a[i])
- if (a[x] < a[y] + a[i])
- ws = 1;
- else
- if (a[y] >= a[i] && a[y] >= a[x])
- if (a[y] < a[x] + a[i])
- ws = 1;
- else
- if (a[i] < a[x] + a[y])
- ws = 1;
- if (ws)
- {
- vector<int> trr(3);
- trr[0] = i;
- trr[1] = x;
- trr[2] = y;
- sort(trr.begin(), trr.end());
- cout << trr[0] + 1 << ' ' << trr[1] + 1 << ' ' << trr[2] + 1 << endl;
- break;
- }
- }
- if (!ws)
- cout << -1 << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement