/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 556.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 183ms 6.184 MiB
#5 Accepted 922ms 41.797 MiB
#6 Accepted 346ms 22.02 MiB
#7 Accepted 67ms 1.031 MiB
#8 Accepted 217ms 21.52 MiB
#9 Accepted 264ms 21.27 MiB
#10 Accepted 278ms 22.27 MiB
#11 Accepted 27ms 532.0 KiB
#12 Accepted 49ms 532.0 KiB
#13 Accepted 1ms 320.0 KiB

Code

// https://judge.eluminatis-of-lu.com/records/66fff6ba966a1d000dac4306

#ifndef LOCAL
#include <bits/stdc++.h>
#define debug(...)
#endif
#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
#define cinv(v) for (auto &it:v) cin>>it;
#define coutv(v) for (auto &it:v) cout<< it<<' '; cout<<'\n';
tree<int, null_type, less_equal<>, rb_tree_tag, tree_order_statistics_node_update> o;
tree<int, null_type, greater_equal<>, rb_tree_tag, tree_order_statistics_node_update> o2;

void shelby() {
    int n;
    cin >> n;
    vector<int> v(n + 1);
    for (int i = 1; i <= n; ++i) cin >> v[i];
    vector cnt(n + 1, vector(2, array<int, 2>()));
    o.clear(), o2.clear();
    for (int i = 1; i <= n; ++i) {
        cnt[i][0][0] = o.order_of_key(v[i]);
        cnt[i][1][0] = o2.order_of_key(v[i]);
        o.insert(v[i]), o2.insert(v[i]);
    }
    o.clear(), o2.clear();
    for (int i = n; i; --i) {
        cnt[i][1][1] = o.order_of_key(v[i]);
        cnt[i][0][1] = o2.order_of_key(v[i]);
        o.insert(v[i]), o2.insert(v[i]);
    }
    vector<int> ans(n + 1);
    for (int i = 1; i <= n; ++i) ans[i] = cnt[i][0][0] * cnt[i][0][1] + cnt[i][1][0] * cnt[i][1][1];
    int q;
    cin >> q;
    while (q--) {
        int x;
        cin >> x;
        cout << ans[x] << '\n';
    }
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    cin >> t;
    for (int _ = 1; _ <= t; ++_) {
        // cout << "Case " << _ << ": ";
        shelby();
    }
}

Information

Submit By
Type
Submission
Problem
P1079 Roy and Query (Easy Version)
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-04 18:30:48
Judged At
2024-10-04 18:30:48
Judged By
Score
100
Total Time
922ms
Peak Memory
41.797 MiB