/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 1ms 532.0 KiB
#3 Wrong Answer 1ms 316.0 KiB
#4 Wrong Answer 171ms 3.434 MiB
#5 Wrong Answer 297ms 7.52 MiB
#6 Wrong Answer 181ms 6.637 MiB
#7 Wrong Answer 65ms 788.0 KiB
#8 Wrong Answer 29ms 2.59 MiB
#9 Wrong Answer 23ms 2.09 MiB
#10 Accepted 250ms 15.27 MiB
#11 Wrong Answer 24ms 532.0 KiB
#12 Wrong Answer 47ms 532.0 KiB
#13 Wrong Answer 1ms 532.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> a(n), prec(n + 1);
        o_set<int> st, st2;
        map<int, int> cnt;

        f(i, n) {
            cin >> a[i];
            cnt[a[i]]++;
            st.insert(a[i]);
        }

        for (int i = 0; i < n; i++) {
            int s1 = st2.order_of_key(a[i]);
            st.erase(st.find(a[i]));
            cnt[a[i]]--;

            ll ts1 = i - (st2.order_of_key(a[i]) - cnt[a[i]]);
            st2.insert(a[i]);

            ll tx = st.order_of_key(a[i]);
            int x = (n - i - 1) - st.order_of_key(a[i]) + cnt[a[i]];
            s1 *= x;
            ts1 *= tx;
            prec[i + 1] = s1 + ts1;
        }

        int q;
        cin >> q;
        while (q--) {
            int m;
            cin >> m;
            if (m <= n)
                cout << prec[m] << '\n';
            else
                cout << 0 << '\n';
        }
    }

    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 17:02:42
Judged At
2024-10-03 17:02:42
Judged By
Score
12
Total Time
297ms
Peak Memory
15.27 MiB