/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 2ms 320.0 KiB
#4 Time Exceeded ≥2086ms ≥1.035 MiB
#5 Time Exceeded ≥2078ms ≥4.316 MiB

Code

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n, q;
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i];

    vector<int> lg(n + 1, 0), ls(n + 1, 0);
    vector<int> rg(n + 1, 0), rs(n + 1, 0);

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j < i; j++) {
            if (a[j] > a[i]) lg[i]++;
            if (a[j] < a[i]) ls[i]++;
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            if (a[j] > a[i]) rg[i]++;
            if (a[j] < a[i]) rs[i]++;
        }
    }

    cin >> q;
    while (q--) {
        int x;
        cin >> x;
        int ans = lg[x] * rs[x] + ls[x] * rg[x];
        cout << ans << endl;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    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:58
Judged At
2024-11-11 02:46:06
Judged By
Score
20
Total Time
≥2086ms
Peak Memory
≥4.316 MiB