Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct answer
- {
- long long good, a,b,c;
- answer():good(0),a(0),b(0),c(0) {};
- };
- int main()
- {
- long long n,q;
- cin >> n >> q;
- vector<long long> v(n);
- for(long long i=0; i<n; i++)
- {
- cin >> v[i];
- }
- vector<pair<pair<long long,long long>,long long> > z(q);
- for(long long i=0; i<q; i++)
- {
- long long l,r;
- cin >> l >> r;
- z[i]= {{l-1,r-1},i};
- }
- sort(z.begin(),z.end());
- set<pair<long long,long long> > cur;
- vector<answer> ans(q);
- long long curl=0, curr=-1;
- for(long long i=0; i<q; i++)
- {
- long long l=z[i].first.first, r=z[i].first.second, num=z[i].second;
- while(curr<r)
- {
- cur.insert({v[curr+1],curr+1});
- curr++;
- }
- while(curl<l)
- {
- cur.erase({v[curl],curl});
- curl++;
- }
- if(curr-curl+1<3)
- {
- continue;
- }
- auto it=cur.begin();
- ++it;
- ++it;
- for(; it!=cur.end(); ++it)
- {
- auto t1=it;
- --t1;
- auto t2=t1;
- --t2;
- if(it->first < t1->first + t2->first)
- {
- ans[num].good=1;
- ans[num].a=it->second;
- ans[num].b=t1->second;
- ans[num].c=t2->second;
- break;
- }
- }
- }
- for(long long i=0; i<q; i++)
- {
- if(ans[i].good)
- {
- cout << ans[i].a+1 << " " << ans[i].b+1 << " " << ans[i].c+1 << "\n";
- }
- else
- {
- cout << "-1\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement