/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 448.0 KiB
#2 Accepted 1ms 320.0 KiB
#3 Accepted 1ms 352.0 KiB
#4 Accepted 143ms 3.156 MiB
#5 Accepted 637ms 15.125 MiB
#6 Accepted 279ms 10.441 MiB
#7 Accepted 58ms 1016.0 KiB
#8 Accepted 138ms 9.938 MiB
#9 Accepted 161ms 9.688 MiB
#10 Accepted 165ms 12.742 MiB
#11 Accepted 22ms 624.0 KiB
#12 Accepted 42ms 668.0 KiB
#13 Accepted 1ms 324.0 KiB

Code

#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;
 
typedef pair<long long,long long> PLL;
typedef long long LL;
 
#define all(v) v.begin(),v.end()
#define faster {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>    

const LL mod = 1e9 + 7;
const int N = 2e5 + 10;
const LL inf = 1e9;

void solve(int test){
    int n, q; cin>>n;
    vector<int> a(n);
    ordered_multiset l, r;
    for(auto &i: a){
        cin>>i;
        r.insert(i);
    }
    cin>>q;
    vector<int> qrs[n];
    for(int i = 0; i < q; i++){
        int u; cin>>u; qrs[--u].push_back(i);
    }
    vector<LL> ans(q);
    for(int i = 0; i < n; i++){
        int x = a[i];
        int pos = r.order_of_key(x);
        r.erase(r.find_by_order(pos));
        int left1 = l.order_of_key(x), left2 = l.size() - l.order_of_key(x + 1);
        int right1 = r.size() - r.order_of_key(x + 1), right2 = r.order_of_key(x);
        LL cur = (1LL * left1 * right1) ;
        cur += (1LL * left2 * right2) ;
        for(auto id: qrs[i]) ans[id] = cur;
        l.insert(x);
    }
    for(auto u: ans) cout<<u<<"\n";
}

signed main(){
    faster
    int t = 1; 
    cin>>t;
    for(int i = 1; i <= t; i++){
        solve(i);
    }
    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:12:39
Judged At
2024-11-11 02:46:34
Judged By
Score
100
Total Time
637ms
Peak Memory
15.125 MiB