QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#453800#5459. Goose, goose, DUCK?WTR2007WA 2ms9896kbC++203.0kb2024-06-24 11:58:492024-06-24 11:58:50

Judging History

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

  • [2024-06-24 11:58:50]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9896kb
  • [2024-06-24 11:58:49]
  • 提交

answer

#include<bits/stdc++.h>
#define L p << 1
#define R p << 1 | 1
#define mid ((l + r) >> 1)
#define int long long
#define fi first
#define se second
#define MULT_TEST 0
using namespace std;
typedef long double ldb;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
const int N = 1000006;
int col[N], tl[N], tr[N], pre[N];
vector<int> E[N];
inline int read() {
    int w = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        w = (w << 1) + (w << 3) + ch - 48;
        ch = getchar();
    }
    return w * f;
}
struct Seg {
    struct node {
        int mn, tag, cnt;
    } tr[N << 2];
    inline void Pushup(int p) {
        tr[p].mn = min(tr[L].mn, tr[R].mn);
        tr[p].cnt = 0;
        if (tr[p].mn == tr[L].mn) tr[p].cnt += tr[L].cnt;
        if (tr[p].mn == tr[R].mn) tr[p].cnt += tr[R].cnt;
    }
    inline void Update(int p, int d) {
        tr[p].mn += d, tr[p].tag += d;
    }
    inline void Pushdown(int p) {
        if (tr[p].tag) {
            Update(L, tr[p].tag);
            Update(R, tr[p].tag);
            tr[p].tag = 0;
        }
    }
    inline void Build(int p, int l, int r) {
        tr[p].mn = 0, tr[p].cnt = r - l + 1;
        if (l == r) return ;
        Build(L, l, mid), Build(R, mid + 1, r);
    }
    inline void Modify(int p, int l, int r, int ql, int qr, int d) {
        if (ql <= l && r <= qr) return Update(p, d), void();
        Pushdown(p);
        if (ql <= mid) Modify(L, l, mid, ql, qr, d);
        if (qr > mid) Modify(R, mid + 1, r, ql, qr, d);
        Pushup(p);
    }
    inline int Query(int p, int l, int r, int ql, int qr) {
        if (ql <= l && r <= qr) return tr[p].cnt;
        Pushdown(p);
        int ans = 0;
        if (ql <= mid) ans += Query(L, l, mid, ql, qr);
        if (qr > mid) ans += Query(R, mid + 1, r, ql, qr);
        return ans;
    }
} A;
inline void Solve() {
    int n, k;
    n = read(), k = read();
    vector<int> T;
    for (int i = 1; i <= n; i++) {
        col[i] = read();
        T.push_back(col[i]);
        E[col[i]].push_back(i);
    }
    sort(T.begin(), T.end());
    T.erase(unique(T.begin(), T.end()), T.end());
    for (auto c : T) {
        int sz = E[c].size();
        for (int i = k - 1; i < sz; i++) {
            tr[E[c][i]] = E[c][i - k + 1];
            tl[E[c][i]] = i == k - 1 ? 1 : E[c][i - k] + 1;
        }
    }
    int ans = 0;
    A.Build(1, 1, n);
    for (int i = 1; i <= n; i++) {
        if (tl[pre[col[i]]])
            A.Modify(1, 1, n, tl[pre[col[i]]], tr[pre[col[i]]], -1);
        pre[col[i]] = i;
        if (tl[i]) A.Modify(1, 1, n, tl[i], tr[i], 1);
        if (A.tr[1].mn == 0) ans += A.Query(1, 1, n, 1, i);
    }
    printf("%lld\n", ans);
}
signed main() {
    int _ = 1;
#if MULT_TEST
    _ = read();
#endif 
    while (_--) Solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 2
1 2 2 1 3 3

output:

10

result:

ok 1 number(s): "10"

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 9896kb

input:

6 1
1 2 3 4 5 6

output:

7

result:

wrong answer 1st numbers differ - expected: '0', found: '7'