QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#689087 | #8781. Element-Wise Comparison | Maybe_Tomorrow | TL | 0ms | 3936kb | C++20 | 985b | 2024-10-30 15:15:09 | 2024-10-30 15:15:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 5;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m; cin >> n >> m;
int idxval[n], validx[n];
for (int i = 0; i < n; i++) {
cin >> idxval[i];
validx[idxval[i]] = i;
}
bitset<N> moveback[n]; // if element at idx i ok w moving back by j
bitset<N> occ; // idx of all visited values
for (int i = n; i; i--) {
int idx = validx[i];
moveback[idx] = occ >> idx;
occ[idx] = 1; // mark cur value as visited
}
bitset<N> sufok[n], prefok[n];
for (int i = n-1; i >= 0; i--) {
if (i % m == m-1 || i == n-1) sufok[i] = moveback[i];
else sufok[i] = (sufok[i+1]&moveback[i]);
}
for (int i = 0; i < n; i++) {
if (i % m == m-1 || i == 0) prefok[i] = moveback[i];
else prefok[i] = (prefok[i-1]&moveback[i]);
}
int ans = 0;
for (int i = 0; i + m - 1 < n; i++) {
ans += (prefok[i+m-1]&sufok[i]).count();
}
cout << ans << "\n";
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3688kb
input:
5 3 5 2 1 3 4
output:
0
result:
ok answer is '0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
5 2 3 1 4 2 5
output:
2
result:
ok answer is '2'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3904kb
input:
4 2 1 2 3 4
output:
3
result:
ok answer is '3'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3936kb
input:
4 2 4 3 2 1
output:
0
result:
ok answer is '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
1 1 1
output:
0
result:
ok answer is '0'
Test #6:
score: -100
Time Limit Exceeded
input:
50000 2 44045 29783 5389 7756 44022 45140 21967 5478 10868 49226 21775 31669 49836 13511 46116 14229 27206 31168 37389 3158 10658 41154 14635 18526 40540 6451 23197 46719 30593 13517 8604 46666 39189 43746 12778 3684 3194 36979 43020 14652 19549 31178 17144 27177 44336 2849 40220 11751 41993 32209 4...
output:
310780127