/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 324.0 KiB
#3 Accepted 1ms 320.0 KiB
#4 Accepted 226ms 5.941 MiB
#5 Accepted 1198ms 40.297 MiB
#6 Accepted 483ms 21.316 MiB
#7 Accepted 76ms 1012.0 KiB
#8 Accepted 278ms 20.77 MiB
#9 Accepted 283ms 20.562 MiB
#10 Accepted 307ms 21.625 MiB
#11 Accepted 31ms 692.0 KiB
#12 Accepted 59ms 728.0 KiB
#13 Accepted 1ms 320.0 KiB

Code

#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>()));
    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]);
    }
    o.clear(), o2.clear();
    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:39:38
Judged At
2024-11-11 02:42:17
Judged By
Score
100
Total Time
1198ms
Peak Memory
40.297 MiB