QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#326509 | #7859. Bladestorm | yllcm | TL | 975ms | 5880kb | C++14 | 1.6kb | 2024-02-13 12:10:25 | 2024-02-13 12:10:25 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define db double
#define ull unsigned long long
#define pb push_back
#define pii pair<int, int>
#define FR first
#define SE second
using namespace std;
inline int read() {
int x = 0; bool op = false;
char c = getchar();
while(!isdigit(c))op |= (c == '-'), c = getchar();
while(isdigit(c))x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return op ? -x : x;
}
const int N = 1e5 + 10;
int n, B, T, m;
int a[N], f[N], L[N], R[N], pos[N], ans[N], dis[N], nxt[N];
int find(int x) {return f[x] == x ? x : f[x] = find(f[x]);}
void build(int id) {
for(int i = R[id]; i >= L[id]; i--) {
int p = min(n, max(i + m, find(i + 1)));
if(p > R[id])dis[i] = 0, nxt[i] = i;
else dis[i] = dis[p] + 1, nxt[i] = nxt[p];
cerr << i << ' ' << p << ' ' << nxt[i] << endl;
}
return ;
}
int query() {
int p = 0, res = 0;
while(find(p + 1) <= n) {
res += dis[p]; p = nxt[p];
if(find(p + 1) <= n)res++, p = min(n, max(p + m, find(p + 1)));
}
// cout << res << endl;
return res;
}
void solve() {
n = read(); m = read();
for(int i = 1; i <= n; i++)a[i] = read();
for(int i = 1; i <= n + 1; i++)f[i] = i;
B = sqrt(n); T = 0;
for(int i = 0; i < n; i += B) {
L[++T] = i; R[T] = min(n - 1, i + B - 1);
for(int j = L[T]; j <= R[T]; j++)pos[j] = T;
build(T);
}
for(int i = n; i; i--) {
ans[i] = query();
f[a[i]] = a[i] + 1;
build(pos[a[i]]);
}
for(int i = 1; i <= n; i++)printf("%d ", ans[i]); putchar('\n');
return ;
}
int main() {
int test = read();
while(test--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5880kb
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 4 5 5
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 975ms
memory: 3804kb
input:
40319 1 1 1 2 1 1 2 2 1 2 1 2 2 1 2 2 2 2 1 3 1 1 2 3 3 1 1 3 2 3 1 2 1 3 3 1 2 3 1 3 1 3 1 2 3 1 3 2 1 3 2 1 2 3 3 2 1 3 2 3 2 2 1 3 3 2 2 3 1 3 2 3 1 2 3 2 3 2 1 3 3 1 2 3 3 3 1 3 2 3 3 2 1 3 3 3 2 3 1 3 3 3 1 2 3 3 3 2 1 4 1 1 2 3 4 4 1 1 2 4 3 4 1 1 3 2 4 4 1 1 3 4 2 4 1 1 4 2 3 4 1 1 4 3 2 4 1 ...
output:
1 1 2 1 2 1 1 1 1 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 1 2 1 2 2 1 1 2 1 2 2 1 2 2 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4...
result:
ok 40319 lines
Test #3:
score: -100
Time Limit Exceeded
input:
50000 10 2 9 3 1 10 2 4 6 5 7 8 10 5 8 3 4 1 2 7 5 9 10 6 10 7 6 7 5 9 1 4 10 2 8 3 10 10 3 1 10 2 6 8 9 4 5 7 10 7 8 9 7 5 6 2 1 10 3 4 10 1 7 1 10 8 9 3 4 6 2 5 10 1 6 7 4 10 3 5 8 9 1 2 10 9 4 6 9 7 3 8 5 1 10 2 10 4 2 6 9 3 10 5 1 4 7 8 10 1 7 4 10 3 6 9 2 5 1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