Submission #845794
Source Code Expand
Copy
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
typedef long long LL;
const int oo = 0x3f3f3f3f;
const int maxn = 100000;
int n;
int a[maxn + 5];
inline void deal()
{
vector<int> u, v;
REP(i, 0, n)
{
if (i & 1) u.pb(a[i]);
else v.pb(a[i]);
}
sort(ALL(u), greater<int>());
sort(ALL(v), greater<int>());
REP(i, 0, n)
{
if (i & 1) a[i] = u.back(), u.pop_back();
else a[i] = v.back(), v.pop_back();
}
}
int main()
{
#ifdef matthew99
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
scanf("%d", &n);
vector<int> v;
REP(i, 0, n)
{
scanf("%d", a + i);
v.pb(a[i]);
}
sort(ALL(v));
REP(i, 0, n) a[i] = lower_bound(ALL(v), a[i]) - v.begin() + 1;
deal();
static int sum[maxn + 5];
memset(sum, 0, sizeof sum);
LL ret = 0;
REP(i, 0, n)
{
for (int j = a[i]; j <= n; j += j & -j) ret += sum[j];
for (int j = a[i]; j > 0; j -= j & -j) ++sum[j];
}
cout << ret << endl;
return 0;
}
Submission Info
Submission Time
2016-08-21 21:21:58+0900
Task
C - BBuBBBlesort!
User
matthew99
Language
C++14 (GCC 5.4.1)
Score
0
Code Size
1460 Byte
Status
WA
Exec Time
73 ms
Memory
1784 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:49:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
./Main.cpp:53:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", a + i);
^
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
72 ms
1784 KB
02.txt
WA
72 ms
1784 KB
03.txt
WA
73 ms
1784 KB
04.txt
WA
73 ms
1784 KB
05.txt
WA
69 ms
1784 KB
06.txt
WA
68 ms
1784 KB
07.txt
WA
68 ms
1784 KB
08.txt
AC
41 ms
1784 KB
09.txt
AC
41 ms
1784 KB
10.txt
AC
41 ms
1784 KB
11.txt
AC
42 ms
1784 KB
12.txt
AC
41 ms
1784 KB
13.txt
AC
40 ms
1784 KB
14.txt
AC
67 ms
1784 KB
15.txt
AC
67 ms
1784 KB
16.txt
AC
67 ms
1784 KB
17.txt
AC
67 ms
1784 KB
18.txt
AC
5 ms
640 KB
19.txt
AC
7 ms
640 KB
20.txt
AC
4 ms
640 KB
21.txt
AC
5 ms
640 KB
22.txt
AC
4 ms
640 KB
s1.txt
AC
5 ms
640 KB
s2.txt
AC
6 ms
640 KB