QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#394732#1363. Bitonic OrderingMahmoudBassemWA 0ms3656kbC++171.8kb2024-04-20 18:38:562024-04-20 18:38:56

Judging History

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

  • [2024-04-20 18:38:56]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3656kb
  • [2024-04-20 18:38:56]
  • 提交

answer

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

using namespace __gnu_pbds;
using namespace std;

// less_equal here isn't related to order_of_key, but to how elements are stored
// swapping here works like this : ors1.swap(ors2);
// NOTE : default order is ascending with no repetition.
template<typename K, typename V, typename Comp = less<K>>
using order_statistic_map = tree<K, V, Comp, rb_tree_tag, tree_order_statistics_node_update>;

template<typename K, typename Comp = less<K>>
using order_statistic_set = order_statistic_map<K, null_type, Comp>;

//#define int long long
#define ld long double
#define el '\n'
#define fi first
#define se second

#define Nine_seconds ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int INF = 1e9;

void run_case(int tc) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    vector<int> pref;
    vector<int> suf;
    order_statistic_set<int> ors;

    for (int i = 0; i < n; i++) {
        pref.emplace_back(ors.size() - ors.order_of_key(a[i]));
        if (i) pref[i] += pref[i - 1];
        ors.insert(a[i]);
    }

    reverse(a.begin(), a.end());
    ors.clear();
    for (int i = 0; i < n; i++) {
        suf.emplace_back(ors.size() - ors.order_of_key(a[i]));
        if (i) suf[i] += suf[i - 1];
        ors.insert(a[i]);
    }

    reverse(suf.begin(), suf.end());

    int ans = INF;

    for (int i = 0; i < n - 1; i++)
        ans = min(ans, pref[i] + suf[i + 1]);

    ans = min(ans, pref[n - 1]);
    ans = min(ans, suf[0]);
    cout << ans << el;
}


int32_t main() {
    Nine_seconds        /*Turn Off for Interactive Problems*/

    int _t = 1;
    //cin >> _t;
    for (int i = 1; i <= _t; i++) {
        run_case(i);
    }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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'