Submission #973586

# Submission time Handle Problem Language Result Execution time Memory
973586 2024-05-02T07:45:11 Z TAhmed33 Global Warming (CEOI18_glo) C++
58 / 100
136 ms 10156 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 25;
#define mid ((l + r) >> 1)
#define tl (node + 1)
#define tr (node + 2 * (mid - l + 1))
struct BIT {
	int tree[MAXN];
	void update (int a, int b) {
		for (; a < MAXN; a += a & (-a)) tree[a] = max(tree[a], b);
	}
	int get (int x) {
		int ret = 0;
		for (; x > 0; x -= x & (-x)) ret = max(ret, tree[x]);
		return ret;
	}
} cur[2];
int n, x, a[MAXN], dp[MAXN][2];
vector <int> comp;
int f (int x) {
	return lower_bound(comp.begin(), comp.end(), x) - comp.begin();
}
void solve () {
	cin >> n >> x;
	for (int i = 1; i <= n; i++) cin >> a[i];
	comp.push_back(-1e9); comp.back()--;
	for (int i = 1; i <= n; i++) {
		comp.push_back(a[i]);
		comp.push_back(a[i] - x);
	}
	sort(comp.begin(), comp.end());
	comp.resize(unique(comp.begin(), comp.end()) - comp.begin());
	int u = comp.size();
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		dp[i][0] = cur[0].get(f(a[i] - x) - 1) + 1;
		dp[i][1] = max(cur[0].get(f(a[i]) - 1), cur[1].get(f(a[i]) - 1)) + 1;
		cur[0].update(f(a[i] - x), dp[i][0]);
		cur[1].update(f(a[i]), dp[i][1]);
		ans = max({ans, dp[i][0], dp[i][1]});
	}
	cout << ans << '\n';
}
signed main () {
	ios::sync_with_stdio(0); cin.tie(0);
	int t = 1; //cin >> t;
	while (t--) solve();
}

Compilation message

glo.cpp: In function 'void solve()':
glo.cpp:33:6: warning: unused variable 'u' [-Wunused-variable]
   33 |  int u = comp.size();
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2512 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2492 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2512 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2512 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2492 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2512 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2512 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2400 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2512 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2492 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2512 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2512 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2400 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2508 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 7316 KB Output is correct
2 Correct 129 ms 7880 KB Output is correct
3 Correct 136 ms 7876 KB Output is correct
4 Correct 133 ms 7868 KB Output is correct
5 Correct 58 ms 6344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 4448 KB Output is correct
2 Correct 33 ms 4316 KB Output is correct
3 Correct 32 ms 4308 KB Output is correct
4 Correct 16 ms 3804 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 16 ms 3912 KB Output is correct
7 Correct 26 ms 4400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 5068 KB Output is correct
2 Correct 69 ms 5328 KB Output is correct
3 Runtime error 50 ms 10156 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2512 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2492 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2512 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2512 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2400 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2508 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 131 ms 7316 KB Output is correct
28 Correct 129 ms 7880 KB Output is correct
29 Correct 136 ms 7876 KB Output is correct
30 Correct 133 ms 7868 KB Output is correct
31 Correct 58 ms 6344 KB Output is correct
32 Correct 32 ms 4448 KB Output is correct
33 Correct 33 ms 4316 KB Output is correct
34 Correct 32 ms 4308 KB Output is correct
35 Correct 16 ms 3804 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 16 ms 3912 KB Output is correct
38 Correct 26 ms 4400 KB Output is correct
39 Correct 69 ms 5068 KB Output is correct
40 Correct 69 ms 5328 KB Output is correct
41 Runtime error 50 ms 10156 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -