QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#59689#1363. Bitonic OrderingSa3tElSefr#WA 2ms3624kbC++201.4kb2022-10-31 19:27:192022-10-31 19:27:19

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-31 19:27:19]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3624kb
  • [2022-10-31 19:27:19]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>

#define ll long long
#define ld  double
using namespace std;

const int N = 2e5 + 5, lg = 19, mod = 998244353;


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

// order_of_key(k): returns the number of elements in the set strictly less than k
// find_by_order(k): returns an iterator to the k-th element (zero-based) in the set

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

    int n;
    cin >> n;
    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++) cin >> a[i];
    vector<ll> pref(n + 1, 0), suff(n + 2, 0);

    ordered_set st;
    for(int i = 1; i <= n; i++) {
        pref[i] = pref[i - 1] + st.order_of_key(-a[i]);
        st.insert(-a[i]);
    }
    st.clear();
    for(int i = n; i >= 1; i--) {
        suff[i] = suff[i + 1] + st.order_of_key(-a[i]);
        st.insert(-a[i]);
    }

    ll ans = min(pref[n], suff[1]);
    // cout << pref[n] << ' ' << suff[1] << ' ';
    for(int i = 1; i + 1 <= n; i++) {
        // cout << i << ' ' << pref[i]  << ' ' << suff[i + 1] << ' ' << pref[i] + suff[i + 1] << '\n';
        ans = min(ans, pref[i] + suff[i + 1]);
    }
    cout << ans;




    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3624kb

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'