QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#487389#8781. Element-Wise Comparisonucup-team4435#WA 1ms3692kbC++201.5kb2024-07-22 21:00:322024-07-22 21:00:33

Judging History

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

  • [2024-07-22 21:00:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3692kb
  • [2024-07-22 21:00:32]
  • 提交

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'