Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define nl "\n"
- #define fi first
- #define se second
- #define pb push_back
- #define ll long long
- #define ull unsigned ll
- #define RV return void
- #define inf 2000000000
- #define sz(x) int(x.size())
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define Mini(x) *min_element(all(x))
- #define Maxi(x) *max_element(all(x))
- #define fixed(n) fixed << setprecision(n)
- #define ceil(w, m) (((w) / (m)) + ((w) % (m) ? 1 : 0))
- #define cin(v) for (auto&i:v) cin >> i;
- #define cout(v) for (auto&i:v) cout << i << " ";
- #define clr(memo, x) memset(memo, x, sizeof memo)
- #define updmin(a, b) a = min(a, b)
- #define updmax(a, b) a = max(a, b)
- #define vi vector < int >
- #define vl vector < ll >
- #define vc vector < char >
- #define vs vector < string >
- #define v2i vector < vector < int > >
- #define v2l vector < vector < int > >
- #define seti set < int >
- #define setl set < ll >
- #define mapii map < int , int >
- #define mapll map < ll , ll >
- #define mapli map < ll , int >
- #define mapci map < char , int >
- #define mapsi map < string , int >
- #define pll pair < ll , ll >
- #define pii pair < int , int >
- #define range(l,r,x) for(int i=l ; i < r ; i+=x)
- #define FastCode ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
- vector < string > ternary= {"NO\n" , "YES\n"};
- void Zainab(){
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- }
- /*================================ solution ================================ */
- struct Data{
- int L , R , Idx;
- };
- void myCode(){
- int n , q;
- cin >> n >> q ;
- vector < ll > v(n) ;
- cin(v);
- // l , r of every subsequence (staify the condition on the problem)
- vector < pair < int , int > > prs ;
- for(int i =0 ; i < n ; i++){
- int st = i;
- i++;
- while(i < n and v[i] >= v[i-1]) i++;
- int idx = i;
- while( i < n and v[i] <=v[i-1]) i++;
- int ni=i-1;
- if(idx !=i){
- while(ni >=0 and v[ni]==v[i-1]){
- ni--;
- }
- }
- if( i !=st ){
- prs.pb({st , i-1});
- }
- i= ni;
- }
- sort(all(prs) , [&](pair < int , int > a , pair < int , int > b){
- return a.se < b.se ;
- });
- // for(auto& [f,s] : prs){
- // cout << f << " " << s << nl;
- // }
- // l , r , index of every query
- vector < Data > query ;
- vector < bool > ans(q);
- for(int i =0 ; i < q ; i++){
- int l ,r ;
- cin >> l >> r;
- l-- , r--;
- // if(l==r or l+1 == r ){
- // // one or two elements only
- // cout << "Yes\n";
- // continue;
- // }
- query.pb({l , r , i});
- }
- sort(all(query) , [&](Data a , Data b){
- return a.R > b.R ;
- });
- set<int> st;
- for(auto[L,R,Idx] : query){
- while(!prs.empty() and prs.back().second >= R)
- st.insert(prs.back().first) , prs.pop_back();
- auto it = st.lower_bound(L);
- ans[Idx] = (it != st.end());
- }
- for(int i =0 ; i < q ; i++){
- cout << (ans[i] ? "Yes\n" : "No\n");
- }
- }
- int main(){
- FastCode ;
- Zainab() ;
- int testCase=1;
- // cin >> testCase ;
- for(int i=1 ; i<= testCase ; i++)
- myCode();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement