/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Wrong Answer 1ms 588.0 KiB
#3 Wrong Answer 1ms 328.0 KiB
#4 Wrong Answer 216ms 8.273 MiB
#5 Accepted 982ms 41.801 MiB
#6 Accepted 359ms 21.922 MiB
#7 Wrong Answer 74ms 1.117 MiB
#8 Accepted 221ms 21.422 MiB
#9 Accepted 238ms 21.18 MiB
#10 Accepted 273ms 22.273 MiB
#11 Wrong Answer 30ms 788.0 KiB
#12 Wrong Answer 55ms 612.0 KiB
#13 Wrong Answer 1ms 540.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]);
    }
    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 15:07:54
Judged At
2024-10-04 15:07:54
Judged By
Score
44
Total Time
982ms
Peak Memory
41.801 MiB