Submission #1519783
Source Code Expand
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
const int INF = (1LL<<30);
const ll LLINF = (1LL<<60);
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;
//#define int ll
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
VI aa, a, unzip(100010);
unordered_map<int, int> zip;
int n;
VI compress() {
a = aa;
sort(ALL(aa));
aa.erase(unique(ALL(aa)), aa.end());
REP(i, aa.size()) {
zip[aa[i]] = i;
unzip[i] = aa[i];
}
REP(i, a.size()) {
a[i] = zip[a[i]];
}
return a;
}
int bit[100010], m = 100010;
//0からi-1番目までの和
int sum(int i) {
i++;
int s = 0;
while(i > 0) {
s += bit[i];
i -= i&-i;
}
return s;
}
//i番目(0-index)にxを加える
void add(int i, int x) {
i++;
while(i <= m) {
bit[i] += x;
i += i&-i;
}
}
signed main(void)
{
cin >> n;
REP(i, n) {
int tmp;
cin >> tmp;
aa.PB(tmp);
}
compress();
VI b, c;
REP(i, n) {
if(i%2) c.PB(a[i]);
else b.PB(a[i]);
}
sort(ALL(b)); sort(ALL(c));
// for(int i: b) cout << i << " "; cout << endl;
// for(int i: c) cout << i << " "; cout << endl;
VI ret;
int i1 = 0, i2 = 0;
REP(i, n) {
if(i%2) ret.PB(c[i1++]);
else ret.PB(b[i2++]);
}
// for(int i: ret) cout << i << " "; cout << endl;
ll ans = 0;
REP(j, n) {
ans += j - sum(ret[j]);
// cout << "j:" << j << " ans:" << ans << " " << sum(ret[j]) << endl;
add(ret[j], 1);
}
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - BBuBBBlesort! |
User |
ferin_tech |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
2121 Byte |
Status |
WA |
Exec Time |
76 ms |
Memory |
7312 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 600 |
Status |
|
|
Set Name |
Test Cases |
Sample |
s1.txt, s2.txt |
All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, s1.txt, s2.txt |
Case Name |
Status |
Exec Time |
Memory |
01.txt |
WA |
75 ms |
7312 KB |
02.txt |
WA |
75 ms |
7312 KB |
03.txt |
WA |
76 ms |
7312 KB |
04.txt |
WA |
75 ms |
7312 KB |
05.txt |
WA |
57 ms |
7312 KB |
06.txt |
WA |
57 ms |
7312 KB |
07.txt |
WA |
57 ms |
7312 KB |
08.txt |
AC |
46 ms |
7312 KB |
09.txt |
AC |
45 ms |
7312 KB |
10.txt |
AC |
45 ms |
7312 KB |
11.txt |
AC |
45 ms |
7312 KB |
12.txt |
AC |
45 ms |
7312 KB |
13.txt |
AC |
45 ms |
7312 KB |
14.txt |
AC |
56 ms |
7312 KB |
15.txt |
AC |
56 ms |
7312 KB |
16.txt |
AC |
56 ms |
7312 KB |
17.txt |
AC |
57 ms |
7312 KB |
18.txt |
AC |
1 ms |
640 KB |
19.txt |
AC |
1 ms |
640 KB |
20.txt |
AC |
1 ms |
640 KB |
21.txt |
AC |
1 ms |
640 KB |
22.txt |
AC |
1 ms |
640 KB |
s1.txt |
AC |
1 ms |
640 KB |
s2.txt |
AC |
1 ms |
640 KB |