Submission #4262331


Source Code Expand

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <bitset>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define rg register
#define LL long long
#define __space putchar(' ')
#define __endl putchar('\n')
template <typename qwq> inline void read(qwq & x)
{
    x = 0;
    rg int f = 1;
    rg char c = getchar();
    while (c < '0' || c > '9')
    {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
    {
        x = (x << 1) + (x << 3) + (c ^ 48);
        c = getchar();
    }
    x *= f;
}
template <typename qaq> inline void print(qaq x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    if (x > 9) print(x / 10);
    putchar(x % 10 + '0');
}
struct node
{
	int val,data;
}a[233333];
int n;
LL ans;
bitset<1000000005> s;
inline bool cmp(node x,node y)//预处理为有序 
{
	return x.val < y.val;
}
int main()
{
	read(n);
	ans = n;
	for (rg int i = 1;i <= n;++i)
	{
		read(a[i].val);
		a[i].data = i;
	}
	stable_sort(a + 1,a + 1 + n,cmp);
	for (rg int i = 1;i <= n;++i)
	{
		if (s[a[i].val]) continue;
		rg bool odd_i = i & 1,odd_data = a[i].data & 1;
		if (odd_i == odd_data) s[a[i].val] = true,--ans;//若位置变化后与变化前的奇偶性相同
		//说明他们必须用操作1才可达到,其余的均可用操作2达到 
	}
	print(ans >> 1);//一个奇数位置需要操作1,定有一个对应的偶数位置需要操作1,故/ 2 
}

Submission Info

Submission Time
Task C - BBuBBBlesort!
User luogu_bot2
Language C++ (GCC 5.4.1)
Score 600
Code Size 1554 Byte
Status AC
Exec Time 50 ms
Memory 123648 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 2
AC × 24
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 AC 50 ms 123520 KB
02.txt AC 49 ms 123520 KB
03.txt AC 50 ms 123520 KB
04.txt AC 50 ms 123520 KB
05.txt AC 46 ms 123520 KB
06.txt AC 46 ms 123520 KB
07.txt AC 46 ms 123520 KB
08.txt AC 39 ms 123520 KB
09.txt AC 39 ms 123520 KB
10.txt AC 40 ms 123520 KB
11.txt AC 40 ms 123520 KB
12.txt AC 40 ms 123520 KB
13.txt AC 39 ms 123520 KB
14.txt AC 45 ms 123648 KB
15.txt AC 46 ms 123520 KB
16.txt AC 46 ms 123520 KB
17.txt AC 45 ms 123520 KB
18.txt AC 32 ms 123136 KB
19.txt AC 32 ms 123136 KB
20.txt AC 32 ms 123136 KB
21.txt AC 32 ms 123136 KB
22.txt AC 32 ms 123136 KB
s1.txt AC 32 ms 123136 KB
s2.txt AC 32 ms 123136 KB