QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#564897 | #7859. Bladestorm | 1234567890# | WA | 1ms | 5724kb | C++14 | 3.0kb | 2024-09-15 16:49:51 | 2024-09-15 16:49:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define mp make_pair
#define inf (ll)1e9
#define pii pair <ll, ll>
#define fr first
#define se second
const ll mod = 1e9 + 7;
char buf[1 << 21], *p1 = buf, *p2 = buf;
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 18, stdin), p1 == p2) ? EOF : *p1++)
inline ll read() {
ll x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9') f = ((ch == '-') ? -1 : f), ch = getchar();
while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return x * f;
}
inline void write(ll x) {
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
inline ll quickmod(ll x, ll y) {
ll Ans = 1;
while(y) {
if(y & 1) Ans = (1ll * Ans * x) % mod;
x = (1ll * x * x) % mod;
y >>= 1;
}
return Ans;
}
inline void Add(ll &x, ll y) {
x += y;
if(x >= mod) x -= mod;
}
inline void Dec(ll &x, ll y) {
x -= y;
if(x < 0) x += mod;
}
inline ll add(ll x, ll y) {
x += y;
if(x >= mod) x -= mod;
return x;
}
inline ll dec(ll x, ll y) {
x -= y;
if(x < 0) x += mod;
return x;
}
ll n, k;
struct Block {
ll M = 400, mx;
ll L[1005], R[1005], pos[100005], cnt;
ll nxt[100005], val[100005], suf[100005], fir[100005];
bool vis[100005];
inline void init() {
mx = 0;
// M = max(3, (ll)sqrt(n));
for(ll i = 1; i <= n; i++) {
pos[i] = i / M + 1;
if(!L[pos[i]]) L[pos[i]] = i;
R[pos[i]] = i;
cnt = pos[i];
}
for(ll i = 0; i <= n; i++) nxt[i] = val[i] = suf[i] = fir[i] = 0, vis[i] = 0;
}
inline ll findnxt(ll p) {
for(ll i = p; i <= cnt; i++) if(fir[i]) return fir[i];
return -1;
}
inline void insert(ll ins) {
ll p = pos[ins];
mx = max(mx, ins);
vis[ins] = 1;
ll Nxt = 0;
for(ll i = ins; i >= L[p]; i--) {
nxt[i] = val[i] = 0;
if(i == R[p]) suf[i] = vis[i];
else suf[i] = suf[i+1] + vis[i];
if(Nxt > i + k) nxt[i] = (nxt[Nxt] ? nxt[Nxt] : Nxt), val[i] = val[Nxt] + 1;
else {
if(i + k <= R[p] && Nxt) nxt[i] = (nxt[i+k] ? nxt[i+k] : (i + k)), val[i] = val[i+k] + 1;
}
if(vis[i]) Nxt = i, fir[p] = i;
}
}
inline void get_ans() {
ll Ans = 0, now = 0, times = 0;
while(now < mx) {
times++;
if(nxt[now]) Ans += val[now], now = nxt[now];
else {
if(now != R[pos[now]] && suf[now+1]) {
now += k, Ans++;
// assert(nxt[now] == 0);
}
else {
ll Nxt = findnxt(pos[now] + 1);
// if(pos[Nxt] == pos[now] || !Nxt) assert(0);
now = max(now + k, Nxt), Ans++;
}
}
}
// if(times >= 1000) {
// printf("%lld\n", times);
// }
write(Ans), putchar(' ');
}
inline void clear() {
for(ll i = 1; i <= cnt; i++) L[i] = R[i] = 0;
}
}B;
int main() {
// freopen("1.in", "r", stdin);
// freopen("1.out", "w", stdout);
ll T = read();
while(T--) {
n = read(), k = read();
B.init();
for(ll i = 1; i <= n; i++) B.insert(read()), B.get_ans();
putchar('\n');
B.clear();
}
return 0;
}
/*
1
9 2
1 2 3 7 8 9 4 5 6
*/
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5724kb
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 '