QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#350774 | #7859. Bladestorm | Charizard2021 | RE | 0ms | 0kb | C++17 | 2.5kb | 2024-03-11 04:00:05 | 2024-03-11 04:00:05 |
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[1 + n];
for(int i = 1; i <= n; i++){
cin >> a[i];
}
int blockSize = sqrt(n);
int idx = 1;
int leftPoint[1 + n];
int rightPoint[1 + n];
int bucket[1 + n];
int minGetOutBucket[1 + n];
for(int i = 1; i <= n + 1; i++){
adj[i] = i;
}
int lastLocation[1 + 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(1 + 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