/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Wrong Answer 2ms 568.0 KiB
#3 Wrong Answer 2ms 484.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-11-11 02:42:48
Judged By
Score
4
Total Time
2ms
Peak Memory
568.0 KiB