QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#394682#1363. Bitonic Orderingrania__#WA 0ms3876kbC++201.6kb2024-04-20 17:40:502024-04-20 17:40:51

Judging History

你现在查看的是最新测评结果

  • [2024-04-20 17:40:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3876kb
  • [2024-04-20 17:40:50]
  • 提交

answer

#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


void doWork() {
    int n;
    cin >> n;
    int arr[n];
    int mx = 0;
    int idx = 0;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        if (arr[i] > mx) {
            mx = arr[i];
            idx = i;
        }
    }
    vector<int> v;
    for (int i = 0; i < n; i++)
        if (i != idx)
            v.push_back(arr[i]);
    ordered_set<int> os;
    vector<long long> pre(n), suf(n);
    pre[0] = 0;
    suf[n - 1] = 0;
    for (int i = 1; i < n; i++) {
        pre[i] = pre[i - 1];
        pre[i] += os.size() - os.order_of_key(v[i - 1]);
        os.insert(v[i - 1]);
    }
    os.clear();
    for (int i = n - 2; i >= 0; i--) {
        suf[i] = suf[i + 1];
        suf[i] += os.size() - os.order_of_key(v[i]);
        os.insert(v[i]);
    }
    long long mn = min(suf[0] + idx, pre[n - 1] + (n - 1 - idx));
    for (int i = 1; i + 1 < n; i++) {
        mn = min(mn, abs(idx - i) + pre[i] + suf[i]);
    }
    cout << mn << '\n';

}


int main() {
    ios::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
//    freopen("bisector.in","r",stdin);
//    freopen("bisector.out","w",stdout);
    int t = 1;
    // cout << primes.size() << endl;
//    cin >> t;
    while (t--) {
        doWork();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3876kb

input:

13
39
40
32
100
13
16
15
28
27
26
25
24
23

output:

15

result:

wrong answer 1st lines differ - expected: '14', found: '15'