QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#623202 | #8781. Element-Wise Comparison | rns_jk | RE | 0ms | 0kb | C++14 | 971b | 2024-10-09 10:35:36 | 2024-10-09 10:35:38 |
answer
#include <bits/stdc++.h>
using namespace std;
#define N 50001
// #define N 5
using ll = long long;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> p(n), q(n);
for (int i = 0; i < n; i++) {
cin >> p[i];
p[i]--;
q[p[i]] = i;
}
vector<bitset<N>> c(n), pre(n + 1), suf(n);
bitset<N> u;
for (int i = 0; i < n; i++) u.set(i);
for (int i = 0; i < n; i++) {
u.set(q[i], false);
c[q[i]] = u;
}
for (int i = 1; i < n; i++) c[i] = c[i] >> i;
for (int i = 0; i < n; i ++) {
if (i % m == 0) suf[i] = c[i];
else suf[i] = suf[i - 1] & c[i];
}
u = 0;
ll ret = 0;
for (int i = n - 1; i >= 0; i--) {
if (i % m == 0) u = c[i];
else u &= c[i];
ret += (u & suf[i + m - 1]).count();
}
cout << ret << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
5 3 5 2 1 3 4