Submission details
Task:Sort
Sender:Diego_09
Submission time:2026-04-17 14:21:29 +0300
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'void solve()':
input/code.cpp:77:13: error: no match for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream<char>'} and 'std::vector<long long int>')
   77 |         cerr<<l<<" "<<r<<"\n";
      |         ~~~~^~~
      |         |     |
      |         |     std::vector<long long int>
      |         std::ostream {aka std::basic_ostream<char>}
In file included from /usr/include/c++/13/istream:41,
                 from /usr/include/c++/13/sstream:40,
                 from /usr/include/c++/13/complex:45,
                 from /usr/include/c++/13/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:127,
                 from input/code.cpp:1:
/usr/include/c++/13/ostream:110:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ostream_type& (*)(__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::...

Code

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#if defined(__has_include)&&__has_include("custom_h/debugging.h")
#define local_run 1
#include "custom_h\debugging.h"
#else 
#define local_run 0
#endif
// #pragma GCC target ("avx2");
// #pragma GCC optimize ("Ofast");
#define rall(v) v.rbegin(),v.rend()
#define all(v) v.begin(),v.end()
#define keyval find_by_order
#define valkey order_of_key
#define int long long
#define pb push_back
#define s second
#define f first

using namespace __gnu_pbds; 
using namespace std;
template<typename T>
using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<typename T>
using omset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
    
void set_io(string name=""){
    ios_base::sync_with_stdio(0);cin.tie(0);
    if(name.size() and !local_run){
        freopen((name+".in").c_str(),"r",stdin);
        freopen((name+".out").c_str(),"w",stdout);
    }
}

const int my[]={0,0,1,-1,1,1,-1,-1};
const int mx[]={1,-1,0,0,1,-1,-1,1};
const int md=1e9+7;
const int oo=1e18;

void solve(){
    int n,q;
    cin>>n>>q;

    vector<int>v(n+1,0),s(n+1,0);
    for(int i=1;i<=n;i++)cin>>v[i];

    s=v;
    sort(all(s));

    while(q--){
        int a,b,xl=0,xr=0;
        cin>>a>>b;

        vector<int>aux=v;

        vector<int>l={0};
        for(int i=1;i<=a;i++)l.pb(aux[i]);
        sort(all(l));
        for(int i=1;i<=a;i++){
            if(aux[i]!=l[i]){
                xl=1;
                aux[i]=l[i];
            }
        }

        vector<int>r={0};
        for(int i=n-b+1;i<=n;i++)r.pb(aux[i]);
        sort(all(l));
        for(int i=n-b+1;i<=a;i++){
            if(aux[i]!=r[i+(b-1)-n]){
                xl=1;
                aux[i]=r[i+(b-1)-n];
            }
        }

        cerr<<l<<" "<<r<<"\n";

        if(aux==s){
            cout<<xl+xr<<"\n";
        }else{
            cout<<"-1\n";
        }
    }
}

int32_t main(){set_io("");
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
}