QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#350777 | #7859. Bladestorm | Charizard2021 | RE | 0ms | 0kb | C++17 | 2.5kb | 2024-03-11 04:01:58 | 2024-03-11 04:02:00 |
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";
}
}
详细
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