/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 532.0 KiB
#2 Accepted 1ms 324.0 KiB
#3 Accepted 2ms 532.0 KiB
#4 Time Exceeded ≥2084ms ≥1.047 MiB
#5 Wrong Answer 1758ms 3.625 MiB

Code

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

void s() {
    int n, q;
    cin >> n;
    vector<int> a(n + 1);

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    cin >> q;
    while (q--) {
        int x, cnt = 0;
        cin >> x;
        vector<int> lg(x, 0), rg(n - x + 1, 0), ls(x, 0), rs(n - x + 1, 0);

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

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

        int lgs = accumulate(lg.begin(), lg.end(), 0);
        int lss = accumulate(ls.begin(), ls.end(), 0);
        int rgs = accumulate(rg.begin(), rg.end(), 0);
        int rss = accumulate(rs.begin(), rs.end(), 0);

        cnt = lgs * rss + lss * rgs;
        cout << cnt << endl;
    }
}

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

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

    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:26:22
Judged At
2024-12-17 11:32:48
Judged By
Score
20
Total Time
≥2084ms
Peak Memory
≥3.625 MiB