QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#59767#1363. Bitonic OrderingziadRE 60ms8816kbC++231.8kb2022-11-01 03:36:212022-11-01 03:36:23

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-01 03:36:23]
  • 评测
  • 测评结果:RE
  • 用时:60ms
  • 内存:8816kb
  • [2022-11-01 03:36:21]
  • 提交

answer

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
#include <climits>
// #pragma GCC optimize ("O3")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
typedef long long ll;
typedef long double ld;
using namespace std;
const int N = 3e5 + 5;

#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 n, pos[N];
vector<int> c;
ordered_set st;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // cout.tie(nullptr);

    cin >> n;
    c.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
        pos[c[i]] = i;
    }
    sort(c.begin(), c.end());
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        int cur_pos = pos[c[i]];
        int less_cnt = st.order_of_key(cur_pos);
        int steps_left = cur_pos - less_cnt;
        int higher_cnt = i - less_cnt;
        int steps_right = n - 1 - cur_pos - higher_cnt;
        ans += min(steps_left, steps_right);
        st.insert(cur_pos);
    }
    cout << ans << '\n';
    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: 0
Accepted
time: 1ms
memory: 3500kb

input:

4
3
2
1
10

output:

2

result:

ok single line: '2'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

13
40
80
90
60
100
20
53
52
51
50
49
48
47

output:

6

result:

ok single line: '6'

Test #4:

score: 0
Accepted
time: 6ms
memory: 4132kb

input:

10000
6048
7145
9278
4540
2505
6384
3715
7910
195
3426
9617
8881
3292
8975
7835
8954
160
5491
760
7767
1502
8277
852
6962
7901
7652
5673
4804
7214
4630
9962
672
6568
5301
179
3767
8589
3256
9022
1215
6827
1809
978
3787
5329
1295
2483
8331
4345
6805
7446
4695
5399
8550
5452
3968
3634
214
1348
6640
91...

output:

12538308

result:

ok single line: '12538308'

Test #5:

score: 0
Accepted
time: 52ms
memory: 8608kb

input:

100000
79611
99198
59215
12212
1068
20968
92768
4976
52551
71627
42534
9227
75293
84258
28203
3971
21644
10476
48090
31870
70655
39717
63939
36338
42901
51351
49298
76460
77186
50374
78750
38146
75785
80387
22773
56976
19956
18105
96559
16337
29650
82378
54109
30126
55031
29411
28918
96418
72024
213...

output:

1253664580

result:

ok single line: '1253664580'

Test #6:

score: 0
Accepted
time: 60ms
memory: 8816kb

input:

100000
100000
99998
99996
99994
99992
99990
99988
99986
99984
99982
99980
99978
99976
99974
99972
99970
99968
99966
99964
99962
99960
99958
99956
99954
99952
99950
99948
99946
99944
99942
99940
99938
99936
99934
99932
99930
99928
99926
99924
99922
99920
99918
99916
99914
99912
99910
99908
99906
9990...

output:

2499950000

result:

ok single line: '2499950000'

Test #7:

score: -100
Runtime Error

input:

20
480659024
557251654
627039283
83671517
815607005
812010293
18889126
899462139
815092936
18782502
811978055
62214200
312916198
215867715
922316200
923490093
51888046
945784009
416508880
272018251

output:


result: