QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#59713#1363. Bitonic Orderingtriplem5dsWA 3ms3568kbC++141.4kb2022-10-31 21:44:432022-10-31 21:44:43

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 21:44:43]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3568kb
  • [2022-10-31 21:44:43]
  • 提交

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]-1);
        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: 100
Accepted
time: 3ms
memory: 3568kb

input:

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

output:

14

result:

ok single line: '14'

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3464kb

input:

4
3
2
1
10

output:

1

result:

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