167232025-05-10 20:06:55algoproTornyokcpp17Accepted 100/100375ms22524 KiB
// UUID: e1080ef1-2688-47ca-9fd1-1a92ac753fee
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n , q;cin >> n >> q;
	vector<array<int , 2>> a;a.push_back({2000000000 , 0});
	for(int i = 0; i < n; i++){
		int y; cin >> y;
		a.push_back({y , i+1});
	}
	a.push_back({2000000000 , n+1});
	stack<int> m;
	m.push(0);
	vector<int> b, c;
	b.push_back(-1);
	for(int i = 1; i <= n; i++){
		while(a[m.top()][0] < a[i][0])m.pop();
		b.push_back(m.top());
		m.push(a[i][1]);
	}
	b.push_back(-1);
	sort(a.begin() , a.end());
	vector<array<int , 2>> qs;
	for(int i = 0; i < q; i++){
		int y; cin >> y;
		qs.push_back({y , i});
	} 
	sort(qs.begin() , qs.end());
	vector<int> ans(q);
	int j = 0 , k = 0;
	vector<int> u(n+2 , 1);
	for(int i = 0; i < q; i++){
		while(qs[i][0] > a[j][0]){
			k = max(k , u[a[j][1]]);
			u[b[a[j][1]]] = max(u[b[a[j][1]]] , u[a[j][1]]+1);
			j++;
		}
		ans[qs[i][1]] = k;
	}
	for(int x : ans)cout << x << " ";

}
SubtaskSumTestVerdictTimeMemory
base100/100
1Accepted0/01ms500 KiB
2Accepted0/0259ms17804 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted6/61ms316 KiB
6Accepted6/61ms316 KiB
7Accepted4/414ms1348 KiB
8Accepted4/423ms1992 KiB
9Accepted8/898ms7000 KiB
10Accepted8/8209ms13728 KiB
11Accepted5/5250ms14216 KiB
12Accepted5/5289ms16268 KiB
13Accepted5/552ms3488 KiB
14Accepted5/5133ms8780 KiB
15Accepted5/5223ms13988 KiB
16Accepted5/5210ms12704 KiB
17Accepted5/5277ms17900 KiB
18Accepted5/5308ms20452 KiB
19Accepted5/5324ms20360 KiB
20Accepted5/5347ms21896 KiB
21Accepted5/5340ms22152 KiB
22Accepted5/5375ms22524 KiB