QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#745858#8781. Element-Wise ComparisonGrand_ElfTL 1ms7944kbC++14853b2024-11-14 12:02:522024-11-14 12:03:00

Judging History

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

  • [2024-11-14 12:03:00]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:7944kb
  • [2024-11-14 12:02:52]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 5e4 + 5;

int n, m, p[N], id[N];
long long ans;
bitset<N> now, f[N], suf[N], pre[N];

bool cmp(int i, int j) {
	return p[i] > p[j];
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> p[i];
		id[i] = i;
	}
	sort(id + 1, id + n + 1, cmp);
	for (int i = 1; i <= n; i++) {
		int j = id[i];
		f[j] = now >> j;
		now[j] = 1;
	}
	pre[0].set();
	suf[0].set();
	for (int i = m - 1; i <= n; i += m - 1) {
		int c = min(n - i, m - 1);
		for (int j = 1; j <= c; j++) {
			pre[j] = pre[j - 1] & f[i + j];
		}
		for (int j = 1; j < m; j++) {
			suf[j] = suf[j - 1] & f[i + 1 - j];
		}
		for (int j = 1; j <= c; j++) {
			ans += (pre[j] & suf[m - j]).count();
		}
	}
	cout << ans << '\n';

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7944kb

input:

5 3
5 2 1 3 4

output:

0

result:

ok answer is '0'

Test #2:

score: 0
Accepted
time: 1ms
memory: 7684kb

input:

5 2
3 1 4 2 5

output:

2

result:

ok answer is '2'

Test #3:

score: 0
Accepted
time: 1ms
memory: 7784kb

input:

4 2
1 2 3 4

output:

3

result:

ok answer is '3'

Test #4:

score: 0
Accepted
time: 1ms
memory: 7908kb

input:

4 2
4 3 2 1

output:

0

result:

ok answer is '0'

Test #5:

score: -100
Time Limit Exceeded

input:

1 1
1

output:


result: