QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#469282#8050. Random PermutationzltWA 914ms6416kbC++141.1kb2024-07-09 17:02:332024-07-09 17:02:33

Judging History

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

  • [2024-07-09 17:02:33]
  • 评测
  • 测评结果:WA
  • 用时:914ms
  • 内存:6416kb
  • [2024-07-09 17:02:33]
  • 提交

answer

#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))

using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;

const int maxn = 300100;

int n, a[maxn], b[maxn], c[maxn << 1];

void solve() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		b[a[i]] = i;
	}
	ll ans = 0;
	for (int i = 1; i <= n; ++i) {
		db x = fabs(i - 1. * (n + 1) / 2) / n;
		int lim = max((ll)(15 / (x * x)), 100LL);
		for (int j = b[i] - 1, s = 0; j >= max(0, b[i] - lim); --j) {
			++c[s + n];
			s += (a[j] <= i ? 1 : -1);
		}
		ll res = 0;
		for (int j = b[i], s = 0; j <= min(n, b[i] + lim); ++j) {
			s += (a[j] <= i ? 1 : -1);
			res += c[-s + n] + c[-s + n + 1];
		}
		ans += res * i;
		for (int j = b[i] - 1, s = 0; j >= max(0, b[i] - lim); --j) {
			--c[s + n];
			s += (a[j] <= i ? 1 : -1);
		}
	}
	printf("%lld\n", ans);
}

int main() {
	int T = 1;
	// scanf("%d", &T);
	while (T--) {
		solve();
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 6000kb

input:

4
1 4 2 3

output:

22

result:

ok 1 number(s): "22"

Test #2:

score: -100
Wrong Answer
time: 914ms
memory: 6416kb

input:

100000
56449 21738 74917 44834 36187 96576 37204 28451 3444 13029 66039 8955 51445 30706 27229 37159 66052 16691 70389 29935 44984 3648 75082 73600 76621 28345 5298 37940 49412 85260 92029 18185 84398 10233 79227 98312 96649 30680 65206 38879 75397 26951 11294 58085 37297 97167 59252 44104 4058 3796...

output:

243975952452370

result:

wrong answer 1st numbers differ - expected: '250202478701074', found: '243975952452370'