/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Runtime Error free(): invalid pointer 1ms 532.0 KiB
#2 Runtime Error free(): invalid pointer 1ms 532.0 KiB
#3 Runtime Error free(): invalid pointer 1ms 532.0 KiB
#4 Runtime Error free(): invalid pointer 3ms 788.0 KiB
#5 Wrong Answer 507ms 11.52 MiB
#6 Wrong Answer 280ms 10.52 MiB
#7 Wrong Answer 119ms 1.02 MiB
#8 Wrong Answer 25ms 2.52 MiB
#9 Wrong Answer 26ms 2.27 MiB
#10 Accepted 404ms 27.77 MiB
#11 Runtime Error free(): invalid pointer 2ms 532.0 KiB
#12 Runtime Error free(): invalid pointer 1ms 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++)
#define trace(x) cerr << #x << ": " << x << '\n'
#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
template <typename T>
using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--)
    {
        o_set<int> st, st2, tst, tst2;
        int n;
        cin >> n;
        vector<int> a(n), prec(n);
        map<int, int> cnt, cnt2;
        f(i, n)
        {
            cin >> a[i];
            cnt[a[i]]++;
            tst.insert(a[i]);
            st.insert(a[i]);
        }
        f(i, n)
        {
            int s1 = st2.order_of_key(a[i]);
            st.erase(st.find(a[i]));
            cnt[a[i]]--;
            ll ts1 = i - (tst2.order_of_key(a[i]) - cnt2[a[i]]);
            tst2.insert(a[i]);
            tst.erase(tst.find(a[i]));
            ll tx = tst.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;
            st2.insert(a[i]);
            // cout << ts1 << ' ' << tx << endl;
        }
        int q;
        cin >> q;
        while (q--)
        {
            int m;
            cin >> m;
            cout << prec[m] << '\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 16:57:24
Judged At
2024-10-03 16:57:24
Judged By
Score
8
Total Time
507ms
Peak Memory
27.77 MiB