/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 16ms 18.77 MiB
#2 Wrong Answer 16ms 18.77 MiB
#3 Wrong Answer 17ms 18.742 MiB
#4 Wrong Answer 191ms 24.664 MiB
#5 Wrong Answer 154ms 63.133 MiB
#6 Wrong Answer 424ms 40.887 MiB
#7 Wrong Answer 86ms 19.215 MiB
#8 Wrong Answer 291ms 40.809 MiB
#9 Accepted 211ms 40.141 MiB
#10 Accepted 171ms 41.254 MiB
#11 Wrong Answer 31ms 18.77 MiB
#12 Wrong Answer 47ms 19.02 MiB
#13 Wrong Answer 17ms 18.812 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pe(c) for (auto &e : c) cout << e << ' '; cout << '\n'
#define ps(b) cout << (b ? "YES" : "NO") << '\n'
#ifdef LOCAL
#include "def.h"
#else
#define ck(...)
#endif
const ll M = 1e9 + 7, N = 2e5 + 5;
long long ar[N], n; vector<long long> tre[N << 2];
auto merge(auto &a, auto &b) {
    int i, j, k = a.size(), l = b.size(); vector<long long> res;
    for (i = 0, j = 0; i < k && j < l;) {
        if (a[i] < b[j]) res.push_back(a[i++]);
        else res.push_back(b[j++]);
    }
    while (i < k) res.push_back(a[i++]);
    while (j < l) res.push_back(b[j++]);
    return res;
}
void make(int nd = 0, int s = 0, int e = n - 1) {
    if (s == e) { tre[nd].push_back(ar[e]); return; }
    int m = (s + e) >> 1, lc = (nd << 1) + 1, rc = lc + 1;
    make(lc, s, m); make(rc, m + 1, e);
    tre[nd] = merge(tre[lc], tre[rc]);
}
void up(int in, long long val, int nd = 0, int s = 0, int e = n - 1) {
    if (s == e) { tre[nd][0] = val; return; }
    int m = (s + e) >> 1, lc = (nd << 1) + 1, rc = lc + 1;
    if (in <= m) up(in, val, lc, s, m);
    else up(in, val, rc, m + 1, e);
    tre[nd] = merge(tre[lc], tre[rc]);
}
int get(int l, int r, long long val, int nd = 0, int s = 0, int e = n - 1) {
    if (l > e || r < s) return 0;
    if (l <= s && e <= r)
        return lower_bound(tre[nd].begin(), tre[nd].end(), val) - tre[nd].begin();
    int m = (e + s) >> 1, lc = (nd << 1) + 1, rc = lc + 1;
    return get(l, r, val, lc, s, m) + get(l, r, val, rc, m + 1, e);
}
int get1(int l, int r, long long val, int nd = 0, int s = 0, int e = n - 1) {
    if (l > e || r < s) return 0;
    if (l <= s && e <= r)
        return lower_bound(tre[nd].begin(), tre[nd].end(), val + 1) - tre[nd].begin();
    int m = (e + s) >> 1, lc = (nd << 1) + 1, rc = lc + 1;
    return get(l, r, val, lc, s, m) + get(l, r, val, rc, m + 1, e);
}
void reset() {
    for (int i = 0; i < (n << 2); ++i) tre[i].clear();
}
void test(int tc) {
    ll o = 0, m = 0, a = 0, b = 0, c = 0, d = 0, i = 0, j = 0, k = 0, q = 0;
    cin >> n;
    // vector<ll> ar(n);
    for (i = 0; i < n; ++i) { cin >> ar[i]; }
    make();
    cin >> q;
    while(q--) {
        d = 0;
        cin >> a; --a;
        b = get(0, a - 1, ar[a]);
        c = (n - a - 1) - get1(a + 1, n - 1, ar[a]);
        d += (b * c);
        b = a - get1(0, a - 1, ar[a]);
        c = get(a + 1, n - 1, ar[a]);
        d += (b * c);
        cout << d << '\n';
    }
    // cout << '\n';
    reset();
}

signed main() {
    cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit | cin.badbit);
    int tc = 0, t = 1;
    cin >> t;
    while (tc < t) test(++tc);
    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:29:16
Judged At
2024-10-03 17:29:34
Judged By
Score
20
Total Time
424ms
Peak Memory
63.133 MiB