QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#460113#8781. Element-Wise Comparisonucup-team2307WA 0ms3708kbC++201.6kb2024-07-01 01:11:072024-07-01 01:11:08

Judging History

你现在查看的是最新测评结果

  • [2024-07-01 01:11:08]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3708kb
  • [2024-07-01 01:11:07]
  • 提交

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'