이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#include <unordered_map>
using namespace std;
#define ll long long
#define open(g) string _name_ = g; freopen((_name_ + ".in").c_str(), "r", stdin); freopen((_name_ + ".out").c_str(), "w", stdout)
#define printArr(a, len) for(int asdf = 0; asdf < (len); ++asdf) cout << (a)[asdf] << ' '; cout << '\n';
#define boost() cin.sync_with_stdio(0); cin.tie(0)
#define forR(i, x) for(int i = 0; i < x; ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(i) i.begin(), i.end()
#define pii pair<int, int>
#define vi vector<int>
#define si set<int>
#define usi unordered_set<int>
#define mii map<int, int>
#define umii unordered_map<int, int>
#define gp_hash_table unordered_map
const int MV = 2e9 + 10, MN = 2e5 + 10;
struct BIT{
vector<int> comp;
int bit[MN];
void init(set<int>& vals){
comp.clear();
for(int& i : bit) i = 0;
for(int i : vals) comp.push_back(i);
}
void upd(int i, int v){
// get array index of i
i = lower_bound(all(comp), i) - comp.begin();
++i;
for(; i < MN; i+=i&-i) bit[i] = max(bit[i], v);
}
int qu(int i){
i = lower_bound(all(comp), i) - comp.begin();
++i;
int ma = 0;
for(; i > 0; i-=i&-i) ma = max(ma, bit[i]);
return ma;
}
};
BIT bit;
int arr[MN], I[MN], D[MN];
signed main(){
int n, x; cin >> n >> x;
forR(i, n) cin >> arr[i];
set<int> vals;
vals.clear();
forR(i, n) vals.insert(arr[i]), vals.insert(arr[i] - 1);
bit.init(vals);
forR(i, n) {
bit.upd(arr[i], I[i] = bit.qu(arr[i] - 1) + 1);
}
vals.clear();
forR(i, n) vals.insert(MV - arr[i]), vals.insert(MV - arr[i] - 1);
bit.init(vals);
for(int i = n - 1; i >= 0; --i){
bit.upd(MV - arr[i], D[i] = bit.qu(MV - arr[i] - 1) + 1);
}
vals.clear();
forR(i, n) vals.insert(arr[i]), vals.insert(arr[i] + x - 1);
bit.init(vals);
int ma = 0;
forR(i, n){
ma = max(ma, bit.qu(arr[i] + x - 1) + D[i]);
bit.upd(arr[i], I[i]);
}
cout << ma << '\n';
}
# | 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... |