/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 536.0 KiB
#2 Accepted 1ms 536.0 KiB
#3 Accepted 1ms 344.0 KiB
#4 Accepted 116ms 5.195 MiB
#5 Accepted 473ms 33.988 MiB
#6 Accepted 210ms 18.141 MiB
#7 Accepted 48ms 912.0 KiB
#8 Accepted 120ms 17.785 MiB
#9 Accepted 216ms 17.43 MiB
#10 Accepted 212ms 18.523 MiB
#11 Accepted 18ms 700.0 KiB
#12 Accepted 33ms 724.0 KiB
#13 Accepted 1ms 324.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 orderedSet = tree<int, null_type, less_equal<int>,
    rb_tree_tag, tree_order_statistics_node_update>;

void pipra(){
    int n;  cin >> n;
    vector<int> a(n);
    for(auto &e: a){
        cin >> e;
    }

    orderedSet oset, oset1;
    vector<int> left_min(n+2), left_max(n+2);
    vector<int> right_min(n+2), right_max(n+2);

    for(int i=1 ; i<=n ; i++){
        int e = a[i-1];
        int mn = oset.order_of_key(e);
        int mx = (int)oset.size() - oset.order_of_key(e+1);
        left_min[i] = mn;
        left_max[i] = mx;
        oset.insert(e);
    }

    for(int i=n ; i>0 ; i--){
        int e = a[i-1];
        int mn = oset1.order_of_key(e);
        int mx = (int)oset1.size() - oset1.order_of_key(e+1);
        right_min[i] = mn;
        right_max[i] = mx;
        oset1.insert(e);
    }

    vector<int> res(n+1);
    for(int i=1 ; i<=n ; i++){
        res[i] = 0;

        // cout << left_min[i-1] << 

        res[i] += left_min[i] * right_max[i];
        res[i] += right_min[i] * left_max[i];
    }

    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)
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-06 20:47:31
Judged At
2024-11-11 02:39:10
Judged By
Score
100
Total Time
473ms
Peak Memory
33.988 MiB