QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#776402 | #7859. Bladestorm | guodong | WA | 0ms | 3488kb | C++17 | 3.2kb | 2024-11-23 18:30:07 | 2024-11-23 18:30:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n,k;
class Block{
public:
vector<pair<int,int>> ans;
vector<int> nxt;
vector<int> mark;
int n;
bool exist = 0;
Block(int _n){
n = _n;
exist = 0;
ans.resize(_n);
nxt.resize(_n);
mark.resize(_n);
}
void calc(){
for(int i = n - 1; i >= 0; --i){
if(mark[i])
nxt[i] = i;
else if(i == n - 1)
nxt[i] = 1e9;
else
nxt[i] = nxt[i + 1];
}
for(int p = 0; p < n; ++p){
int st = p,cnt = 0,flag = 0;
while(1){
if(st == n-1 || nxt[st + 1] == 1e9){
ans[p] = make_pair(cnt,st);
break;
}
if(st + k >= n){
ans[p] = make_pair(cnt + 1,st + k);
break;
}
if(nxt[st + k] == nxt[st]){
st = nxt[st];
}
else{
st = st + k;
}
++cnt;
}
}
}
void add(int x){
exist = 1;
if(mark[x])
return;
mark[x] = 1;
calc();
}
pair<int,int> getAns(int st){
return ans[st];
}
bool Exist(){
return exist;
}
};
signed main()
{
#ifdef NICEGUODONG
freopen("data.in","r",stdin);
#endif
// ios::sync_with_stdio(false);
int T;
cin >> T;
while(T--){
cin >> n >> k;
int len;
if(k * k > n || n <= 3){
len = n;
}
else{
len = sqrt(n);
}
len = n;
vector<Block> block((n + len - 1) / len + 1, Block(len));
int maxx = 0;
for(int i = 1; i <= n; ++i){
int x;
cin >> x;
maxx = max(maxx,x);
block[x / len].add(x % len);
int cur = 0,ans = 0,id = 0,ext = 0;
while(cur < maxx){
int l = id * len;
if(block[id].exist == 0){
++id;
ext = 1;
continue;
}
if(ext == 1){
ext = 0;
ans++;
cur = block[id].nxt[0] + l;
}
if(cur >= l){
auto &[fee,nxt] = block[id].ans[cur - l];
ans += fee;
cur = nxt + l;
}
else{
cur = max(cur + k,block[id].nxt[0] + l);
++ans;
auto &[fee,nxt] = block[id].ans[cur - l];
ans += fee;
cur = nxt + l;
}
++id;
}
cout << ans << " ";
}
cout << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3488kb
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 1 2 3 3 3 3 3 4 4 4 4 1 1 2 3 4 4 5 5 5
result:
wrong answer 3rd lines differ - expected: '1 1 2 3 4 4 4 5 5', found: '1 1 2 3 4 4 5 5 5 '