QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#113367#5459. Goose, goose, DUCK?kemunikuWA 3ms11024kbC++202.7kb2023-06-17 11:01:112023-06-17 11:01:14

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-17 11:01:14]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:11024kb
  • [2023-06-17 11:01:11]
  • 提交

answer

/* author: kyawa */
#include<bits/stdc++.h>
using namespace std;

/*
 考察
 K個前の値が同じ要素のindexはダブリングで求まる。

 */

template<class S, S (*op)(S, S), S (*e)()>
class SegmentTree{
public:
    vector<S> table;
    int64_t size = 1;
    SegmentTree(vector<S> vec){
        while(size < vec.size()) size <<= 1;
        table.resize(size << 1, e());
        for(int64_t i = 0; i < (int64_t)vec.size(); i++) table[i + size] = vec[i];
        for(int64_t i = size - 1; i >= 1; i--) table[i] = op(table[i<<1|0],table[i<<1|1]);
    }
    SegmentTree(int64_t siz){
        while(size < siz) size <<= 1;
        table.resize(size << 1, e());
        for(int64_t i = 0; i < siz; i++) table[i + size] = e();
        for(int64_t i = size - 1; i >= 1; i--) table[i] = op(table[i<<1|0],table[i<<1|1]);
    }
    S fold(int64_t l, int64_t r){
        l += size; r += size;
        S Lres = e(), Rres = e();
        while(l < r){
            if(l & 1) Lres = op(Lres, table[l++]);
            if(r & 1) Rres = op(table[--r], Rres);
            l >>= 1; r >>= 1;
        }
        return op(Lres, Rres);
    }
    void set(int64_t p, S x){
        p += size;
        table[p] = x;
        while(p >>= 1) table[p] = op(table[p<<1|0],table[p<<1|1]);
    }
};

int64_t op(int64_t a, int64_t b){
    return max(a, b);
}

int64_t e(){
    return INT64_MIN;
}

int main(){
    int64_t res = 0;
    int64_t N, K; cin >> N >> K; K--;
    if(K == 0){
        cout << 0 << '\n';
        return 0;
    }
    vector<int64_t> A(N); for(auto &a : A) cin >> a;
    vector<int64_t> prv(1000001, -1);
    vector<vector<int64_t>> dbl(30, vector<int64_t>(N));
    for(int64_t i = 0; i < N; i++){
        dbl[0][i] = prv[A[i]];
        prv[A[i]] = i;
    }
    for(int64_t i = 1; i < 30; i++){
        for(int64_t j = 0; j < N; j++){
            dbl[i][j] = (dbl[i-1][j] == -1 ? -1 : dbl[i-1][dbl[i-1][j]]);
        }
    }
    vector<int64_t> K_prvidx(N); for(int64_t i = 0; i < N; i++) K_prvidx[i] = i;
    bitset<30> kbit(K);
    for(int64_t b = 0; b < 30; b++){
        if(kbit[b]){
            for(int64_t i = 0; i < N; i++){
                if(K_prvidx[i] == -1) continue;
                K_prvidx[i] = dbl[b][K_prvidx[i]];
            }
        }
    }
    SegmentTree<int64_t,op,e> seg(K_prvidx);
    for(int64_t L = 0; L < N; L++){
        int64_t pass = L, fail = N+1;
        while(fail - pass > 1){
            int64_t mid = pass + (fail - pass) / 2;
            if(seg.fold(L, mid) < L){
                pass = mid;
            }else{
                fail = mid;
            }
        }
        res += (pass - L);
    }
    cout << res << '\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 11024kb

input:

6 2
1 2 2 1 3 3

output:

10

result:

ok 1 number(s): "10"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3424kb

input:

6 1
1 2 3 4 5 6

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 11012kb

input:

100 10
142826 764475 142826 986320 764475 142826 142826 986320 764475 986320 764475 764475 764475 142826 142826 986320 764475 986320 764475 764475 142826 764475 142826 764475 986320 986320 764475 142826 764475 764475 142826 764475 764475 986320 142826 142826 142826 142826 764475 986320 986320 764475...

output:

1943

result:

wrong answer 1st numbers differ - expected: '4309', found: '1943'