QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#405536 | #7859. Bladestorm | dnialh# | WA | 1ms | 3508kb | C++23 | 3.2kb | 2024-05-06 06:24:10 | 2024-05-06 06:24:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
#define sq(a) ((a)*(a))
#define per(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rep(i,a,b) for (int i=a; i<b; i++)
#define FOR(i,a,b) for (int i=a; i<b; i++)
#define F0R(i,a) for (int i=0; i<a; i++)
#define ROF(i,a,b) for (int i = (b)-1; i >= a; i--)
#define R0F(i,a) for (int i = (a)-1; i >= 0; i--)
#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << endl, 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << endl;
#define _ << " _ " <<
#define ll long long
template<class T> bool ckmin(T&a, T&b) { bool B = a > b; a = min(a,b); return B; }
template<class T> bool ckmax(T&a, T&b) { bool B = a < b; a = max(a,b); return B; }
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ld,ld> pld;
typedef complex<ld> cd;
typedef vector<int> vi;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
const ld PI = acos(-1.0);
const ld EPS = 1e-7;
const int MOD = 998244353;
const int SZ = 300;
struct UF {
vi e;
vi top;
UF(int n) : e(n, -1) {
top = vi(n);
F0R(i, n) top[i] = i;
}
bool sameSet(int a, int b) { return find(a) == find(b); }
int size(int x) { return -e[find(x)]; }
int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
bool join(int a, int b) {
a = find(a), b = find(b);
if (a == b) return false;
if (e[a] > e[b]) swap(a, b);
e[a] += e[b]; e[b] = a;
top[a] = max(top[a], top[b]);
return true;
}
int nex(int a){
return top[find(a + 1)];
}
};
void solve(){
int n, k;
cin >> n >> k;
vector<int> a(n);
F0R(i, n) {
cin >> a[i];
}
int o_n = n;
n += k + k + 10;
UF adj(n + 2);
//vector<int> nx(n + 1, 1);
//vector<int> prev(n + 2, 1);
vector<int> jmp(n + SZ, 1);
vector<int> ct(n + SZ, 0);
vector<int> alive(n + 2, 1);
F0R(i, n + SZ){
jmp[i] = i;
ct[i] = 0;
}
FOR(i, o_n + 1, n){
adj.join(i, i + 1);
}
const int CT = 1 + (n / SZ);
F0R(i, CT){
ROF(j, SZ * i, min(n + 1, SZ * (i + 1))){
// break;
int u = max(j + k, adj.nex(j));
if (u / SZ == i){
jmp[j] = jmp[u];
ct[j] = ct[u] + 1;
}
}
}
vi ans;
R0F(i, o_n){
int ind = 0;
int ret = -1;
if (k >= 0){
while (ind < n){
//cout << ind << " ";
ret += 1;
ind = max(ind + k, adj.nex(ind));
if (ind >= n) break;
ret += ct[ind];
ind = jmp[ind];
}
//cout << endl;
ans.pb(ret);
}
//Finish
int curr = a[i];
alive[curr] = 0;
adj.join(curr, curr + 1);
int bl = curr/SZ;
ROF(j, SZ * bl, min(n + 1, SZ * (bl + 1))){
int u = max(j + k, adj.nex(j));
if (u / SZ == bl){
jmp[j] = jmp[u];
ct[j] = ct[u] + 1;
} else {
jmp[j] = j;
ct[j] = 0;
}
}
}
reverse(all(ans));
for (auto v : ans) cout << v << " ";
cout << '\n';
}
int32_t main() { FAST
int t;
cin >> t;
while (t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3508kb
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:
2 3 4 4 5 5 5 2 3 4 4 4 4 4 5 5 5 5 2 2 3 4 5 5 5 6 6
result:
wrong answer 1st lines differ - expected: '1 2 3 3 4 4 4', found: '2 3 4 4 5 5 5 '