QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#487389 | #8781. Element-Wise Comparison | ucup-team4435# | WA | 1ms | 3692kb | C++20 | 1.5kb | 2024-07-22 21:00:32 | 2024-07-22 21:00:33 |
Judging History
answer
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int N = 5e4;
using B = bitset<N>;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<int> p(n);
for (int i = 0; i < n; ++i) {
cin >> p[i];
--p[i];
}
vector<B> a(n);
vector<int> ord(n);
for (int i = 0; i < n; ++i) {
ord[p[i]] = i;
}
B tmp{};
for (int i = 0; i < n; ++i) {
a[ord[i]] = tmp;
tmp[ord[i]] = 1;
}
tmp = 0;
for (int i = 0; i < n; ++i) {
a[i] &= tmp;
tmp[i] = 1;
a[i] <<= n - i;
}
vector<B> suf(n), pref(n);
for (int sep = m; sep <= n; sep += m) {
B g = a[sep - 1];
for (int i = sep - 1; i >= sep - m; --i) {
if (i != sep - 1) {
g &= a[i];
}
suf[i] = g;
}
if (sep < n) {
g = a[sep];
for (int i = sep; i < min(n, sep + m); ++i) {
if (i != sep) {
g &= a[i];
}
pref[i] = g;
}
}
}
ll ans = 0;
int sep = m;
for (int i = 0; i + m <= n; ++i) {
while (sep <= i) {
sep += m;
}
ans += (sep < i + m ? (suf[i] & pref[i + m]).count() : suf[i].count());
}
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3640kb
input:
5 3 5 2 1 3 4
output:
0
result:
ok answer is '0'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3692kb
input:
5 2 3 1 4 2 5
output:
1
result:
wrong answer expected '2', found '1'