QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#363378#7859. BladestormredwhiteWA 1ms5680kbC++173.4kb2024-03-23 21:40:462024-03-23 21:40:47

Judging History

你现在查看的是最新测评结果

  • [2024-03-23 21:40:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5680kb
  • [2024-03-23 21:40:46]
  • 提交

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<<endl;
	}
}

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(b[wh] < b[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<<endl;
	}
}

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};
	}
}

int main () {
	ios_base::sync_with_stdio(false), cin.tie(0);

	cin>>t;
	while(t--) {
		solve();
		//reset();
	}

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5680kb

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:

wrong answer 1st lines differ - expected: '1 2 3 3 4 4 4', found: '1'