QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#394771#1363. Bitonic OrderingZuqa#WA 1ms3828kbC++201.7kb2024-04-20 19:26:472024-04-20 19:26:48

Judging History

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

  • [2024-04-20 19:26:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3828kb
  • [2024-04-20 19:26:47]
  • 提交

answer

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

#define el '\n'
#define FIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned uint;
typedef __int128 bint;
typedef long double ld;
typedef complex<ld> pt;
typedef unsigned long long ull;

template<typename T, typename X>
using hashTable = gp_hash_table<T, X>;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

// mt19937_64 for unsigned long long
mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());

void doWork()
{
    int n;
    cin >> n;
    vector<ll> suff(n);
    ordered_set<int> a, b;
    vector<int> v(n), mx(n);
    for(int i = 0; i < n; i++)
        cin >> v[i];


    for(int i = n - 1; i >= 0; i--)
    {
        mx[i] = v[i];
        suff[i] = b.size() - b.order_of_key(v[i]);
        b.insert(v[i]);

        if(i + 1 < n)
            suff[i] += suff[i + 1], mx[i] = max(mx[i], mx[i + 1]);
    }

    ll ans = suff[0], invA = 0;
    for(int i = 0; i + 1 < n; i++)
    {
        invA += a.size() - a.order_of_key(v[i]);
        a.insert(v[i]);

        if(*a.rbegin() > mx[i + 1])
            ans = min(ans, invA + suff[i + 1]);
    }

    invA += a.size() - a.order_of_key(v.back());
    ans = min(ans, invA);

    cout << ans;

}

signed main()
{
    FIO
    int T = 1;
//    cin >> T;
    for(int i = 1; i <= T; i++)
        doWork();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3828kb

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'