QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#350778 | #7859. Bladestorm | Charizard2021 | RE | 0ms | 0kb | C++17 | 2.6kb | 2024-03-11 04:11:29 | 2024-03-11 04:11:30 |
answer
#include<bits/stdc++.h>
using namespace std;
int end(int x, vector<int>& adj){
if(adj[x] == x){
return x;
}
return adj[x] = end(adj[x], adj);
}
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];
vector<int> adj(2 + n);
for(int i = 1; i <= 1 + n; 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, adj)));
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, adj) <= n){
ans += minGetOutBucket[cur];
cur = lastLocation[cur];
if(end(cur + 1, adj) <= n){
ans++;
cur = min(n, max(cur + k, end(cur + 1, adj)));
}
}
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, adj)));
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:
1 2 3 3 4 4 4