| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1291798 | nqc | Global Warming (CEOI18_glo) | C++20 | 105 ms | 6116 KiB |
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define debug(x) cout << #x << " = " << x << '\n'
#define all(a) a.begin(), a.end()
#define SZ(a) (int)(a).size()
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const ll inf64 = 3e18;
const int inf32 = 2e9 + 5;
int n, X, a[N];
struct FenwickTree {
int n;
vector<int> node;
FenwickTree() {}
FenwickTree(int n) : n(n), node(n + 3, 0) {}
void upd(int i, int x) {
for(; i <= n; i += i & (-i))
node[i] = max(node[i], x);
}
int get(int i) {
int res = 0;
for(; i; i -= i & (-i))
res = max(res, node[i]);
return res;
}
};
void solve() {
cin >> n >> X;
vector<int> cprs;
for(int i = 1; i <= n; i++) {
cin >> a[i];
cprs.push_back(a[i]);
cprs.push_back(a[i] + X);
}
sort(all(cprs)); cprs.erase(unique(all(cprs)), cprs.end());
auto take = [&](int val) -> int {
return lower_bound(all(cprs), val) - cprs.begin() + 1;
};
int ans = 0;
FenwickTree fen0(SZ(cprs)), fen1(SZ(cprs));
for(int i = 1; i <= n; i++) {
int p = take(a[i]), q = take(a[i] + X);
int dp0 = fen0.get(p - 1) + 1;
int dp1 = max(fen1.get(p - 1) + 1, fen0.get(q - 1) + 1);
ans = max({ans, dp0, dp1});
fen0.upd(p, dp0);
fen1.upd(p, dp1);
}
cout << ans << '\n';
}
int main() {
auto start = chrono::steady_clock::now();
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen("input.txt", "r")) {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
int test = 1;
// cin >> test;
while(test--) solve();
chrono::duration<double> elapsed {chrono::steady_clock::now() - start};
cerr << "\n>> Runtime: " << elapsed.count() << "s\n";
}
컴파일 시 표준 에러 (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... | ||||
