QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#715583#9584. 顾影自怜sea_birdWA 170ms22856kbC++202.2kb2024-11-06 12:40:192024-11-06 12:40:19

Judging History

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

  • [2024-11-06 12:40:19]
  • 评测
  • 测评结果:WA
  • 用时:170ms
  • 内存:22856kb
  • [2024-11-06 12:40:19]
  • 提交

answer

#include<bits/stdc++.h>
typedef long long ll;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
const int maxn = 1e6 + 1000;
#define ls p<<1
#define rs p<<1|1
std::vector<int>pos[maxn];
int a[maxn];
int tree[maxn << 2];
void up(int p) {
    tree[p] = std::max(tree[ls], tree[rs]);
}
void build(int l, int r, int p) {
    if (l >= r) {
        tree[p] = a[l];
        return;
    }
    int m = (l + r) >> 1;
    build(l, m, ls);
    build(m + 1, r, rs);
    up(p);
}
int query(int L, int l, int r, int p, int val) {
    if (r < L)return -1;
    if (L <= l) {
        if (tree[p] <= val)return -1;
        if (l >= r)return l;
    }
    int m = (l + r) >> 1;
    int ans = query(L, l, m, ls, val);
    if (ans != -1)return ans;
    return query(L, m + 1, r, rs, val);
}
int mquery(int L, int l, int r, int p, int val) {
    //找到第一个小于L的大于等于val的数
    if (l > L)return -1;
    if (r <= L) {
        if (tree[p] <= val)return -1;
        if (l >= r)return l;
    }
    int m = (l + r) >> 1;
    int ans = mquery(L, m + 1, r, rs, val);
    if (ans != -1)return ans;
    return mquery(L, l, m, ls, val);
}
void solve() {
    int n, k;
    std::cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        pos[i].clear();
        std::cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
        pos[a[i]].push_back(i);
    }
    ll ans = 0LL;
    build(1, n, 1);

    for (int i = 1; i <= n; i++) {
        int siz = pos[i].size();
        for (int j = 0; (j + k - 1) < siz; j++) {
            int r = query(pos[i][j], 1, n, 1, i);
            if (r == -1)r = n + 1;
            int l = pos[i][j + k - 1];
            int lf = pos[i][j];
            if (lf != 1) {
                lf = mquery(lf - 1, 1, n, 1, i);
                if (lf == -1) {
                    lf = 0;
                }
            }
            else {
                lf = 0;
            }
            ans += std::max(0LL, (ll)(r - l)) * (pos[i][j] - lf);
        }
    }
    std::cout << ans << "\n";
}
int main() {
    std::ios::sync_with_stdio(0);
    std::cin.tie(0), std::cout.tie(0);
    int t = 1;
    std::cin >> t;
    while (t--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 5692kb

input:

2
5 2
1 3 3 2 2
4 3
1 4 2 1

output:

7
0

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 170ms
memory: 22856kb

input:

1
1000000 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

166667166667000000

result:

wrong answer 1st lines differ - expected: '500000500000', found: '166667166667000000'