/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Wrong Answer 2ms 540.0 KiB
#3 Wrong Answer 1ms 332.0 KiB
#4 Wrong Answer 108ms 2.184 MiB
#5 Wrong Answer 189ms 5.48 MiB
#6 Wrong Answer 124ms 4.312 MiB
#7 Wrong Answer 50ms 920.0 KiB
#8 Wrong Answer 25ms 2.086 MiB
#9 Wrong Answer 24ms 2.23 MiB
#10 Wrong Answer 165ms 8.809 MiB
#11 Wrong Answer 21ms 620.0 KiB
#12 Wrong Answer 37ms 624.0 KiB
#13 Wrong Answer 1ms 328.0 KiB

Code

// PIPRA ||  HABIB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define int        long long int
#define pb         push_back
#define all(x)     x.begin(),x.end()
#define allr(x)    x.rbegin(),x.rend()
#define ii         pair<int,int>
#define endl       "\n"

template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for (const auto &x : v) os << " " << x;
        return os << '}';
}
using orderedTree = tree<int, null_type, less<int>, 
rb_tree_tag, tree_order_statistics_node_update>;

void pipra(){
    int n;  cin >> n;
    vector<int> a(n);
    orderedTree left, right;
    for(auto &e: a){
        cin >> e;
        right.insert(e);
    }


    vector<int> res(n+1);
    for(int i=1 ; i<=n ; i++){
        int e = a[i-1];
        right.erase(right.find(e));

        int x = 0;
        x += min(left.order_of_key(e), right.size() - right.order_of_key(e+1));
        x += min(right.order_of_key(e), left.size() - left.order_of_key(e+1));

        res[i] = x;
        left.insert(e);
    }

    int q;  cin >> q;
    while(q--){
        int i;  cin >> i;
        cout << res[i] << endl;
    }
}

int32_t main(){
    // HABIB
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); cout.tie(NULL);

    int t;    cin>>t;
    while(t--) {
        pipra();
    }
    return 0 ;
}

Information

Submit By
Type
Submission
Problem
P1079 Roy and Query (Easy Version)
Contest
Brain Booster #6
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-03 17:00:52
Judged At
2024-10-03 17:00:52
Judged By
Score
4
Total Time
189ms
Peak Memory
8.809 MiB