QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#460111#8781. Element-Wise Comparisonucup-team2307WA 127ms3964kbC++201.6kb2024-07-01 00:38:112024-07-01 00:38:11

Judging History

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

  • [2024-07-01 00:38:11]
  • 评测
  • 测评结果:WA
  • 用时:127ms
  • 内存:3964kb
  • [2024-07-01 00:38:11]
  • 提交

answer

#pragma GCC target ("avx2")
#include "immintrin.h"
#include <bits/stdc++.h>
using namespace std;

const int N=5e4+100;

uint16_t p[N];
uint16_t cnt[N],ans[N];

using mi=__m256i;

void iter(uint16_t i, uint16_t lim, uint16_t m) {
    mi v_1 = _mm256_set1_epi16(1);
    mi v_pi = _mm256_set1_epi16(p[i]);
    mi v_m1 = _mm256_set1_epi16(m - 1);
    uint16_t d = 1;
    for (; d + 15 <= lim; d += 16) {
        mi v_pdi = _mm256_loadu_si256((__m256i*)(p + d + i));
        mi v_ok = _mm256_cmpgt_epi16(v_pdi, v_pi);
        mi v_cntd = _mm256_loadu_si256((__m256i*)(cnt + d));
        v_cntd = _mm256_add_epi16(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_epi16(v_cntd, v_m1), v_1);
        v_ansd = _mm256_add_epi16(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);

    uint16_t n,m;
    cin >> n >> m;

#if 1 // real use
    for (uint16_t i = 0; i < n; i++)
        cin >> p[i];
#else // random test
    for (uint16_t i = 0; i < n; i++)
        p[i] = i;
    mt19937 rng;
    shuffle(p, p + n, rng);
#endif

    for (uint16_t i = 0; i < n; i++)
        iter(i, min(n - m, n - i - 1), m);
    cout << accumulate(ans, ans + n, 0LL);
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3556kb

input:

5 3
5 2 1 3 4

output:

0

result:

ok answer is '0'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3740kb

input:

5 2
3 1 4 2 5

output:

2

result:

ok answer is '2'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3732kb

input:

4 2
1 2 3 4

output:

3

result:

ok answer is '3'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

4 2
4 3 2 1

output:

0

result:

ok answer is '0'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3732kb

input:

1 1
1

output:

0

result:

ok answer is '0'

Test #6:

score: -100
Wrong Answer
time: 127ms
memory: 3964kb

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:

314734177

result:

wrong answer expected '310780127', found '314734177'