QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#578172#7579. Nonsense Timeskip2004AC ✓7198ms218072kbC++201.3kb2024-09-20 17:09:422024-09-20 17:09:43

Judging History

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

  • [2024-09-20 17:09:43]
  • 评测
  • 测评结果:AC
  • 用时:7198ms
  • 内存:218072kb
  • [2024-09-20 17:09:42]
  • 提交

answer

#include<bits/stdc++.h>
namespace rgs = std::ranges;
using std::cin, std::cout;
using ll = long long;
using u64 = unsigned long long;
using db = double;
const int N = 50005;
const int M = sqrt(N) * 2 + 100;
int p[N], k[N], t[N];
int n;
struct bit {
	int bit[N];
	void add(int p, int v) {
		for(;p <= n;p += p & -p) {
			bit[p] = std::min(bit[p], v);
		}
	}
	int qry(int p) {
		int ans = 1e9;
		for(;p;p &= p - 1) {
			ans = std::min(ans, bit[p]);
		}
		return ans;
	}
	void init() {
		std::fill(bit + 1, bit + n + 1, 1e9);
	}
} bit[M];
int dp[N][M];
int ans[N];
void solve() {
	cin >> n;
	for(int i = 1;i <= n;++i) {
		cin >> p[i];
	}
	for(int i = 1;i <= n;++i) {
		cin >> k[i];
		t[k[i]] = i;
	}
	for(int i = 0;i < M;++i) bit[i].init();
	for(int i = 0;i < M;++i) {
		dp[0][i] = i ? n + 1 : 0;
		bit[i].add(1, dp[0][i]);
	}
	for(int i = 1;i <= n;++i) {
		for(int j = 1;j < M;++j) {
			dp[i][j] = std::max(t[i], bit[j - 1].qry(p[i]));
		}
		for(int j = 1;j < M;++j) {
			bit[j].add(p[i], dp[i][j]);
		}
	}
	for(int i = 1, la = 1;i < M;++i) {
		int lim = bit[i].qry(n);
		for(;la < lim;++la) {
			ans[la] = i - 1;
		}
	}
	for(int i = 1;i <= n;++i) {
		cout << ans[i] << " \n"[i == n];
	}
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0);
	int T; cin >> T;
	for(int i = 0;i < T;++i) {
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 110148kb

input:

1
5
2 5 3 1 4
1 4 5 3 2

output:

1 1 2 3 3

result:

ok 5 number(s): "1 1 2 3 3"

Test #2:

score: 0
Accepted
time: 7198ms
memory: 218072kb

input:

3
50000
22166 21423 37322 49151 2245 43507 37354 30961 32198 31003 32257 22468 27730 18919 2196 31303 3176 37808 4455 10088 18018 39466 29912 379 1832 17454 15968 4355 43806 24661 23628 14892 28610 44878 34190 33667 21697 4707 35211 12330 30832 8775 39434 26352 44030 31455 41042 11966 1147 39695 240...

output:

1 2 2 2 2 2 2 3 4 4 5 6 6 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 8 9 9 9 10 11 11 12 12 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 14 14 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 16 16 16 17 17 17 17 17 17 17 18 18 18 18...

result:

ok 150000 numbers