QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#363389 | #7859. Bladestorm | redwhite | WA | 0ms | 5724kb | C++17 | 3.4kb | 2024-03-23 21:47:01 | 2024-03-23 21:47:03 |
Judging History
answer
/*
IN THE NAME OF GOD
*/
#include <bits/stdc++.h>
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;
#define F first
#define S second
#define Mp make_pair
#define pb push_back
#define pf push_front
#define size(x) ((ll)x.size())
#define all(x) (x).begin(),(x).end()
#define kill(x) cout << x << '\n', exit(0);
#define fuck(x) cout << "(" << #x << " , " << x << ")" << endl
#define endl '\n'
const int N = 1e5+23, SQ = 350, lg = 18;
const int SQI = N/SQ;
ll Mod = 1e9+7; //998244353;
inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
ll ans = 1;
a=MOD(a, mod);
while (b) {
if (b & 1) ans = MOD(ans*a, mod);
b >>= 1;
a = MOD(a*a, mod);
}
return ans;
}
int t, n, k, cntb, a[N], dp[N], b[N], l[N], r[N], blazy[N], lazy[N];
pii pd[N];
set<int> st;
void updmin(int x) {
int id = 1;
while(id <= cntb && r[id] < x) {
blazy[id] = min(blazy[id], x);
id++;
}
if(id <= cntb) {
for(int i=l[id]; i<x; i++) lazy[i] = min(lazy[i], x);
}
}
void solve1() {
int mxnow = 0;
for(int i=0; i<=n; i++) st.insert(i);
for(int i=1; i<=n; i++) {
mxnow = max(mxnow, a[i]);
updmin(a[i]);
for(int j=a[i]-1; j>=0&&j>=a[i]-k; j--) {
if(st.find(j) == st.end()) break;
st.erase(j);
dp[j] = j+k;
}
int wh = 0, ans = 0;
while(wh <= mxnow-1) {
wh = max(wh+k, min({dp[wh], lazy[wh], blazy[b[wh]]}));
ans++;
}
cout<<ans<<' ';
}
}
void update(int id) {
for(int i=r[id]; i>=l[id]; i--) {
int tp = max(i+k, min(blazy[b[i]], lazy[i]));
if(tp > r[id]) pd[i] = {tp, 1};
else pd[i] = Mp(pd[tp].F, pd[tp].S+1);
}
}
void solve2() {
int mxnow = 0;
for(int i=0; i<=n; i++) st.insert(i);
for(int i=1; i<=n; i++) {
mxnow = max(mxnow, a[i]);
updmin(a[i]);
for(int j=a[i]-1; j>=0&&j>=a[i]-k; j--) {
if(st.find(j) == st.end()) break;
st.erase(j);
dp[j] = j+k;
}
update(b[a[i]]);
if(b[a[i]] > 0) update(b[a[i]] - 1);
int wh = 0, ans = 0;
while(min({pd[wh].F, lazy[wh], blazy[b[wh]]}) < mxnow) {
ans += pd[wh].S;
wh = min({pd[wh].F, lazy[wh], blazy[b[wh]]});
}
while(wh < mxnow) {
ans++;
wh = max(wh+k, min({dp[wh], lazy[wh], blazy[b[wh]]}));
}
cout<<ans<<' ';
}
}
void solve() {
cin>>n>>k;
for(int i=1; i<=n; i++) cin>>a[i];
for(int i=0; i<=n; i+=SQ) {
cntb++;
l[cntb] = i, r[cntb] = min(i+SQ-1, n);
blazy[cntb] = n+1;
for(int j=i; j<i+SQ&&j<=n; j++) {
dp[j] = n+1;
b[j] = cntb;
lazy[j] = n+1;
pd[j] = {n+1, 1};
}
}
if(k >= SQ) solve1();
else solve2();
st.clear();
for(int i=0; i<=n+1; i++) {
cntb = a[i] = dp[i] = b[i] = l[i] = r[i] = blazy[i] = lazy[i] = 0;
pd[i] = {0, 0};
}
cout<<endl;
}
int main () {
ios_base::sync_with_stdio(false), cin.tie(0);
cin>>t;
while(t--) {
solve();
//reset();
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
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 5 7 11 14 16 1 2 5 7 9 11 14 18 21 25 26 1 2 4 8 13 15 20 23 25
result:
wrong answer 1st lines differ - expected: '1 2 3 3 4 4 4', found: '1 2 5 7 11 14 16 '