Submission #44212293


Source Code Expand

// LUOGU_RID: 118885458
#include<bits/stdc++.h>
#define LL long long
#define DB double
#define MOD 1000000007
#define ls(x) x << 1
#define rs(x) x << 1 | 1
#define lowbit(x) x & (-x)
#define PII pair<int, int>
#define MP make_pair
#define VI vector<int>
#define VII vector<int>::iterator
#define all(x) x.begin(), x.end()
#define EB emplace_back
#define SI set<int>
#define SII set<int>::iterator
#define QI queue<int>
using namespace std;
template<typename T> void chkmn(T &a, const T &b) { (a > b) && (a = b); }
template<typename T> void chkmx(T &a, const T &b) { (a < b) && (a = b); }
int inc(const int &a, const int &b) { return a + b >= MOD ? a + b - MOD : a + b; }
int dec(const int &a, const int &b) { return a - b < 0 ? a - b + MOD : a - b; }
int mul(const int &a, const int &b) { return 1LL * a * b % MOD; }
int sqr(const int &a) { return 1LL * a * a % MOD; }
void Inc(int &a, const int &b) { ((a += b) >= MOD) && (a -= MOD); }
void Dec(int &a, const int &b) { ((a -= b) < 0) && (a += MOD); }
void Mul(int &a, const int &b) { a = 1LL * a * b % MOD; }
void Sqr(int &a) { a = 1LL * a * a % MOD; }
int qwqmi(int x, int k = MOD - 2)
{
	int res = 1;
	while(k)
	{
		if(k & 1) Mul(res, x);
		Sqr(x), k >>= 1;
	}
	return res;
}
const int N = 3e3 + 5;
const int inv2 = (MOD + 1) / 2;
int n, Q, a[N];
int f[N][N], ans;
int main()
{
	scanf("%d %d", &n, &Q);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
			f[i][j] = (a[i] > a[j]);
	for(int cas = 1; cas <= Q; ++cas)
	{
		int x, y;
		scanf("%d %d", &x, &y);
		if(x > y) swap(x, y);
		f[x][y] = f[y][x] = mul(inc(f[x][y], f[y][x]), inv2);
		for(int i = 1; i <= n; ++i)
		{
			if(i == x || i == y) continue;
			f[x][i] = f[y][i] = mul(inc(f[x][i], f[y][i]), inv2);
			f[i][x] = f[i][y] = mul(inc(f[i][x], f[i][y]), inv2);
		}
	}
	for(int i = 1; i < n; ++i)
		for(int j = i + 1; j <= n; ++j)
			Inc(ans, f[i][j]);
	Mul(ans, qwqmi(2, Q));
	printf("%d\n", ans);
	return 0;
}

Submission Info

Submission Time
Task D - Inversion Sum
User Schucking_Sattin
Language C++ (GCC 9.2.1)
Score 1000
Code Size 2049 Byte
Status AC
Exec Time 345 ms
Memory 38972 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:45:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   45 |  scanf("%d %d", &n, &Q);
      |  ~~~~~^~~~~~~~~~~~~~~~~
./Main.cpp:47:8: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   47 |   scanf("%d", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~
./Main.cpp:54:8: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   54 |   scanf("%d %d", &x, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 3
AC × 39
Set Name Test Cases
Sample s1.txt, s2.txt, s3.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, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 280 ms 38940 KiB
02.txt AC 274 ms 38808 KiB
03.txt AC 270 ms 38888 KiB
04.txt AC 241 ms 38780 KiB
05.txt AC 281 ms 38768 KiB
06.txt AC 254 ms 38876 KiB
07.txt AC 286 ms 38796 KiB
08.txt AC 273 ms 38896 KiB
09.txt AC 261 ms 38848 KiB
10.txt AC 298 ms 38884 KiB
11.txt AC 276 ms 38864 KiB
12.txt AC 281 ms 38900 KiB
13.txt AC 263 ms 38768 KiB
14.txt AC 272 ms 38756 KiB
15.txt AC 270 ms 38952 KiB
16.txt AC 330 ms 38836 KiB
17.txt AC 293 ms 38764 KiB
18.txt AC 345 ms 38876 KiB
19.txt AC 295 ms 38948 KiB
20.txt AC 323 ms 38912 KiB
21.txt AC 326 ms 38964 KiB
22.txt AC 300 ms 38884 KiB
23.txt AC 271 ms 38748 KiB
24.txt AC 317 ms 38852 KiB
25.txt AC 320 ms 38844 KiB
26.txt AC 293 ms 38872 KiB
27.txt AC 311 ms 38916 KiB
28.txt AC 321 ms 38784 KiB
29.txt AC 288 ms 38972 KiB
30.txt AC 295 ms 38760 KiB
31.txt AC 278 ms 38948 KiB
32.txt AC 265 ms 38968 KiB
33.txt AC 304 ms 38888 KiB
34.txt AC 264 ms 38952 KiB
35.txt AC 3 ms 3680 KiB
36.txt AC 2 ms 3684 KiB
s1.txt AC 2 ms 3684 KiB
s2.txt AC 2 ms 3720 KiB
s3.txt AC 2 ms 3664 KiB