/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 488.0 KiB
#2 Wrong Answer 2ms 324.0 KiB
#3 Wrong Answer 2ms 324.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<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void sufi() {
    ordered_set 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], 0ll});
        pre1[i] = les;
        int gr = s.size() - s.order_of_key({ara[i] + 1, 0ll});
        pre2[i] = gr;
        s.insert({ara[i], 0ll});
    }


    ordered_set 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], 0ll});
        pre3[i] = les;
        int gr = s2.size() - s2.order_of_key({ara[i] + 1, 0ll});
        pre4[i] = gr;
        s2.insert({ara[i], 0ll}); 
    }

   
    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:44:05
Judged At
2024-11-11 02:47:42
Judged By
Score
4
Total Time
2ms
Peak Memory
488.0 KiB