QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#350777#7859. BladestormCharizard2021RE 0ms0kbC++172.5kb2024-03-11 04:01:582024-03-11 04:02:00

Judging History

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

  • [2024-03-11 04:02:00]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-03-11 04:01:58]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int adj[100005];
int end(int x){
    if(adj[x] == x){
        return x;
    }
    return adj[x] = end(adj[x]);
}
int main(){
    int t;
    cin >> t;
    while(t--){
        int n, k;
        cin >> n >> k;
        int a[10 + n];
        for(int i = 1; i <= n; i++){
            cin >> a[i];
        }
        int blockSize = sqrt(n);
        int idx = 1;
        int leftPoint[10 + n];
        int rightPoint[10 + n];

        int bucket[10 + n];
        int minGetOutBucket[10 + n];
        for(int i = 1; i <= n + 1; i++){
            adj[i] = i;
        }
        int lastLocation[10 + n];
        for(int i = 0; i < n; i += blockSize){
            leftPoint[idx] = i;
            rightPoint[idx] = min(n - 1, i + blockSize - 1);
            for(int j = leftPoint[idx]; j <= rightPoint[idx]; j++){
                bucket[j] = idx;
            }
            for(int j = rightPoint[idx]; j >= leftPoint[idx]; j--){
                int nextPoint = min(n, max(j + k, end(j + 1)));
                if(nextPoint >= rightPoint[idx] + 1){
                    minGetOutBucket[j] = 0;
                    lastLocation[j] = j;
                }
                else{
                    minGetOutBucket[j] = minGetOutBucket[nextPoint] + 1;
                    lastLocation[j] = lastLocation[nextPoint];
                }
            }
            idx++;
        }
        vector<int> thing(10 + n);
        for(int i = n; i >= 1; i--){
            int ans = 0;
            int cur = 0;
            while(end(cur + 1) <= n){
                ans += minGetOutBucket[cur];
                cur = lastLocation[cur];
                if(end(cur + 1) <= n){
                    ans++;
                    cur = min(n, max(cur + k, end(cur + 1)));
                }
            }
            thing[i] = ans;
            adj[a[i]] = a[i] + 1;
            for(int j = rightPoint[bucket[a[i]]]; j >= leftPoint[bucket[a[i]]]; j--){
                int nextPoint = min(n, max(j + k, end(j + 1)));
                if(nextPoint >= rightPoint[bucket[a[i]]] + 1){
                    minGetOutBucket[j] = 0;
                    lastLocation[j] = j;
                }
                else{
                    minGetOutBucket[j] = minGetOutBucket[nextPoint] + 1;
                    lastLocation[j] = lastLocation[nextPoint];
                }
            }
        }
        for(int i = 1; i <= n; i++){
            cout << thing[i] << " ";
        }
        cout << "\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

3
7 2
4 7 3 6 1 2 5
11 3
10 7 4 9 6 8 5 1 3 2 11
9 2
1 2 3 7 8 9 4 5 6

output:


result: