QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#460113 | #8781. Element-Wise Comparison | ucup-team2307 | WA | 0ms | 3708kb | C++20 | 1.6kb | 2024-07-01 01:11:07 | 2024-07-01 01:11:08 |
Judging History
answer
#pragma GCC target ("avx2")
#include "immintrin.h"
#include <bits/stdc++.h>
using namespace std;
const int N=5e4+100;
int32_t p[N];
int32_t cnt[N],ans[N];
using mi=__m256i;
void iter(int32_t i, int32_t lim, int32_t m) {
mi v_1 = _mm256_set1_epi32(1);
mi v_pi = _mm256_set1_epi32(p[i]);
mi v_m1 = _mm256_set1_epi32(m - 1);
int32_t d = 1;
for (; d + 15 <= lim; d += 8) {
mi v_pdi = _mm256_loadu_si256((__m256i*)(p + d + i));
mi v_ok = _mm256_cmpgt_epi32(v_pdi, v_pi);
mi v_cntd = _mm256_loadu_si256((__m256i*)(cnt + d));
v_cntd = _mm256_add_epi32(v_cntd, v_1);
v_cntd = _mm256_and_si256(v_cntd, v_ok);
_mm256_storeu_si256((__m256i*)(cnt + d), v_cntd);
mi v_ansd = _mm256_loadu_si256((__m256i*)(ans + d));
mi v_cmp = _mm256_and_si256(_mm256_cmpgt_epi32(v_cntd, v_m1), v_1);
v_ansd = _mm256_add_epi32(v_ansd, v_cmp);
_mm256_storeu_si256((__m256i*)(ans + d), v_ansd);
}
for (; d <= lim; d++) {
bool ok = p[i] < p[d + i];
cnt[d] = (cnt[d] + 1) * ok;
ans[d] += (cnt[d] >= m);
}
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int32_t n,m;
cin >> n >> m;
#if 0 // real use
for (int32_t i = 0; i < n; i++)
cin >> p[i];
#else // random test
for (int32_t i = 0; i < n; i++)
p[i] = i;
mt19937 rng;
shuffle(p, p + n, rng);
#endif
for (int32_t i = 0; i < n; i++)
iter(i, min(n - m, n - i - 1), m);
cout << accumulate(ans, ans + n, 0LL);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3708kb
input:
5 3 5 2 1 3 4
output:
0
result:
ok answer is '0'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3560kb
input:
5 2 3 1 4 2 5
output:
0
result:
wrong answer expected '2', found '0'