Submission #1284866

#TimeUsernameProblemLanguageResultExecution timeMemory
1284866Sir_Ahmed_ImranGift Exchange (JOI24_ho_t4)C++17
50 / 100
2595 ms6404 KiB
            //    01001100 01001111 01010100 01000001    \\
            //                                           \\
            //                ╦  ╔═╗╔╦╗╔═╗               \\
            //                ║  ║ ║ ║ ╠═╣               \\
            //                ╩═╝╚═╝ ╩ ╩ ╩               \\
            //                                           \\
            //    01001100 01001111 01010100 01000001    \\
 
#include <bits/stdc++.h>
using namespace std;
#define N 100001
#define nl '\n'
#define ff first
#define ss second
#define ll long long
#define ld long double
#define terminator main
#define pll pair<ll,ll>
#define add insert
#define append push_back
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int a[N];
int b[N];

bool query(){
    int n, m, o, l, r;
    cin >> l >> r;
    n = r - l + 1;
    vector<pii> v;
    vector<int> u;
    for(int i = l; i <= r; i++){
        v.append({a[i], b[i]});
        u.append(b[i]);
    }
    m = n - 1;
    sort(all(v));
    sort(all(u));
    /*
    for(int i = 0; i < n; i++)
        cout << '(' << v[i].ff << ',' << v[i].ss << ") ";
    cout << nl;
    for(int i = 0; i < n; i++)
        cout << u[i] << ' ';
    cout << nl;
    */
    set<int> Q;
    for(int i = n - 1; i >= 0; i--){
        while(m >= 0 && v[m].ff > u[i]){
            Q.add(v[m].ss);
            m--;
        }
        o = 0;
        for(auto & j : Q){
            if(j != u[i]){
                o = j;
                break;
            }
        }
        if(!o) return 0;
        Q.erase(o);
    }
    return 1;
}

void solve(){
    int n, q;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i <= n; i++)
        cin >> b[i];
    cin >> q;
    while(q--){
        if(query())
            cout << "Yes\n";
        else cout << "No\n";
    }
}

int terminator(){
    L0TA;
    int T = 1;
    //cin >> T;
    while(T--)
        solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...