QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#745858 | #8781. Element-Wise Comparison | Grand_Elf | TL | 1ms | 7944kb | C++14 | 853b | 2024-11-14 12:02:52 | 2024-11-14 12:03:00 |
Judging History
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;
}
详细
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