/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 1ms 324.0 KiB
#3 Accepted 2ms 320.0 KiB
#4 Accepted 227ms 4.086 MiB
#5 Accepted 436ms 26.477 MiB
#6 Accepted 364ms 14.414 MiB
#7 Accepted 129ms 916.0 KiB
#8 Accepted 281ms 13.824 MiB
#9 Accepted 313ms 13.73 MiB
#10 Accepted 320ms 14.465 MiB
#11 Accepted 45ms 592.0 KiB
#12 Accepted 87ms 676.0 KiB
#13 Accepted 1ms 320.0 KiB

Code

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace std;
using namespace __gnu_pbds;
const ll md=1e9+7;
const ll smpl=4*1e5;
const ll p=31;


typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>pbds;

void sufi() {
    pbds s;
    int n;
    cin >> n;
    ll ara[n+1];
    ll pre1[n+1] = {0};
    ll pre2[n+1] = {0};


    for (int i = 1; i <= n; i++) {
        cin >> ara[i];

        int les = s.order_of_key(ara[i]);
        pre1[i] = les;
        int gr = s.size() - s.order_of_key(ara[i] + 1);
        pre2[i] = gr;
        s.insert(ara[i]);
    }


    pbds s2;
    ll pre3[n+1] = {0};
    ll pre4[n+1] = {0};
    for (int i = n; i >= 1; i--) {
        int les = s2.order_of_key(ara[i]);
        pre3[i] = les;
        int gr = s2.size() - s2.order_of_key(ara[i] + 1);
        pre4[i] = gr;
        s2.insert(ara[i]);
    }


    int q;
    cin >> q;
    while (q--) {
        ll i;
        cin >> i;
        ll ans = pre1[i] * pre4[i];
        ans += pre2[i] * pre3[i];
        cout << ans << endl;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--)
    sufi();
    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 16:51:06
Judged At
2024-11-11 02:47:24
Judged By
Score
100
Total Time
436ms
Peak Memory
26.477 MiB