Submission #1022885

# Submission time Handle Problem Language Result Execution time Memory
1022885 2024-07-14T07:09:57 Z vjudge1 Radio Towers (IOI22_towers) C++17
0 / 100
4000 ms 267880 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;

const int maxn = 1e5 + 100;

int n, k;
int a[maxn];
int t[maxn];
int dp[maxn];
vector<pii> g[maxn];
int l[maxn];
int r[maxn];
int pref[maxn];

void upd(int i, int x){
	for(; i <= n; i |= (i + 1)) t[i] = max(t[i], x);
}

int get(int i){
	int res = 0;
	for(; i > 0; i = (i & (i + 1)) - 1) res = max(res, t[i]);
	return res;
}

void init(int N, std::vector<int> H){
	n = N; 
	for(int i = 1; i <= n; i++){
		a[i] = H[i-1];
	}
	k = 1;
	while(k < n && a[k+1] > a[k]) k++;
	for(int i = k + 1; i <= n; i++){
		if(a[i-1] < a[i]) k = 0;
	}
	for(int i = 1; i <= n; i++){
		pref[i] = pref[i-1];
		if(a[i] < min(a[i+1], a[i-1])) pref[i]++;
	}
}

int max_towers(int L, int R, int D){
	if(L == R) return 1;
	if(k){
		if(L < k && k < R) return 2;
		return 1;
	}
	L++; R++;
	if(D == 1){
		int ans = pref[R-1] - pref[L];
		if(a[L] < a[L+1]) ans++;
		if(a[R] < a[R-1]) ans++;
		return ans;
	}
	for(int i = 1; i <= n; i++){
		t[i] = 0;
		g[i].clear();
	}
	vector<int> v;
	for(int i = L; i <= R; i++){
		while(v.size() && a[v.back()] <= a[i]) v.pop_back();
		v.push_back(i);
		l[i] = L - 1;
		for(int tl = 0, tr = v.size() - 1; tl <= tr;){
			int mid = (tl + tr) >> 1;
			if(a[v[mid]] - D < a[i]) tr = mid - 1;
			else tl = mid + 1, l[i] = v[mid];
		}
	}
	v.clear();
	for(int i = R; i >= L; i--){
		while(v.size() && a[v.back()] <= a[i]) v.pop_back();
		v.push_back(i);
		r[i] = R + 1;
		for(int tl = 0, tr = v.size() - 1; tl <= tr;){
			int mid = (tl + tr) >> 1;
			if(a[v[mid]] - D < a[i]) tr = mid - 1;
			else tl = mid + 1, r[i] = v[mid];
		}
	}
	int ans = 0;
	for(int i = L; i <= R; i++){
		for(auto [p, x]: g[i]){
			upd(p, x);
		}
		dp[i] = get(l[i]) + 1;
		g[r[i]].push_back({i, dp[i]});
		ans = max(ans, dp[i]);
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 291 ms 5208 KB 2nd lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4436 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4524 KB Output is correct
12 Incorrect 2 ms 4440 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4436 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4524 KB Output is correct
12 Incorrect 2 ms 4440 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 540 ms 5720 KB Output is correct
2 Correct 661 ms 5720 KB Output is correct
3 Correct 683 ms 4952 KB Output is correct
4 Correct 617 ms 5720 KB Output is correct
5 Correct 622 ms 5720 KB Output is correct
6 Correct 751 ms 5720 KB Output is correct
7 Correct 661 ms 5720 KB Output is correct
8 Correct 644 ms 5720 KB Output is correct
9 Incorrect 665 ms 5720 KB 32125th lines differ - on the 1st token, expected: '1', found: '2'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4066 ms 267880 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4436 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4524 KB Output is correct
12 Incorrect 2 ms 4440 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 291 ms 5208 KB 2nd lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -