| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1291538 | thaibeo123 | Global Warming (CEOI18_glo) | C++20 | 101 ms | 6040 KiB |
#include <bits/stdc++.h>
using namespace std;
#define NAME "A"
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define MASK(x) (1ll << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
const int N = 2e5 + 5;
struct FenwickTree {
int n;
vector<int> fen;
FenwickTree(int n): n(n), fen(n + 1) {}
void update(int x, int v) {
for (int i = x; i <= n; i += i & -i) {
fen[i] = max(fen[i], v);
}
}
int get(int x) {
int res = 0;
for (int i = x; i > 0; i -= i & -i) {
res = max(res, fen[i]);
}
return res;
}
};
int n, x;
int a[N];
vector<int> vals;
int getid(int x) {
return upper_bound(all(vals), x) - vals.begin();
}
void input() {
cin >> n >> x;
for (int i = 1; i <= n; i++) {
cin >> a[i];
vals.pb(a[i]);
vals.pb(a[i] - x);
}
sort(all(vals));
vals.erase(unique(all(vals)), vals.end());
}
void solve() {
FenwickTree one(vals.size()), two(vals.size());
int ans = 0;
for (int i = 1; i <= n; i++) {
int cur = max(one.get(getid(a[i]) - 1), two.get(getid(a[i]) - 1)) + 1;
ans = max(ans, cur);
two.update(getid(a[i]), cur);
cur = one.get(getid(a[i] - x) - 1) + 1;
one.update(getid(a[i] - x), cur);
ans = max(ans, cur);
}
cout << ans;
}
signed main() {
if (fopen(NAME".INP", "r")) {
freopen(NAME".INP", "r", stdin);
freopen(NAME".OUT", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
int t = 1;
//cin >> t;
while (t--) {
input();
solve();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
