이 제출은 이전 버전의 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
#define gp_hash_table unordered_map
const int MV = 2e9 + 10, MN = 2e5 + 10;
gp_hash_table<int, int> bit;
void upd(int i, int v){
++i;
for(; i > 0 && i < MV; i+=i&-i) {
bit[i] = max(bit[i], v);
}
}
int qu(int i){
++i;
int ma = 0;
for(; i > 0; i-=i&-i) {
ma = max(ma, bit[i]);
}
return ma;
}
int arr[MN], I[MN], D[MN];
signed main(){
int n, x; cin >> n >> x;
bit.clear();
forR(i, n) cin >> arr[i];
forR(i, n) upd(arr[i], I[i] = qu(arr[i] - 1) + 1);
bit.clear();
for(int i = n - 1; i >= 0; --i){
upd(MV - arr[i], D[i] = qu(MV - arr[i] - 1) + 1);
}
bit.clear();
int ma = 0;
forR(i, n){
ma = max(ma, qu(arr[i] + x - 1) + D[i]);
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... |