이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include<unordered_map>
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define rrep(i,a,b) for(int i=int(a);i>int(b);i--)
#define trav(a,v) for(auto& a: v)
#define sz(v) v.size()
#define all(v) v.begin(),v.end()
#define vi vector<int>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const long long inf = 1e15;
using namespace std;
vector<ll> p(1e6);
vector<ll> Ur(1e6);
ll UfindSet(ll cur) {
if (p[cur] == cur)return cur;
return p[cur] = UfindSet(p[cur]);
}
void Umerge(ll j, ll i) {
ll sj = UfindSet(j);
ll si = UfindSet(i);
if (Ur[sj] > Ur[si])swap(sj, si);
p[sj] = si;
Ur[si]++;
return;
}
struct tree {
typedef ll T;
static constexpr T unit = -inf;
T f(T a, T b) { return max(a, b); }
vector<T> s;
ll n;
tree(ll n=0, T def=unit) : n(n),s(2*n,def){}
void update(ll pos, T val) {
for (s[pos += n] = val; pos /= 2;) {
s[pos] = f(s[pos * 2], s[pos * 2 + 1]);
}
}
T query(ll l, ll r) {
T a = unit, b = unit;
for (l += n, r += n; l < r; l /= 2, r /= 2) {
if (l % 2)a = f(a, s[l++]);
if (r % 2)b = f(b, s[--r]);
}
return f(a, b);
}
};
int main() {
cin.sync_with_stdio(false);
int n, d;
cin >> n >> d;
vector<pair<ll, int>> v(n);
rep(i, 0, n) {
cin >> v[i].first;
v[i].second = -i;
}
sort(all(v));
vector<ll> dp(n, -inf);
rep(i, 0, 1e6)p[i] = i;
tree seg(n);
rep(i, 0, n) {
dp[-v[i].second] = 1;
ll cur = d;
int end = max(-1, -v[i].second - d-1 );
rrep(j, -v[i].second, end) {
Umerge(end+1, j);
if (p[j] != j)break;
}
ll left = -v[i].second - 1;
ll l = 0, r = -v[i].second - 1;
while (l <= r) {
ll mid = l + (r - l) / 2;
if (UfindSet(mid) == UfindSet(-v[i].second)) {
left = mid;
r = mid - 1;
}
else l = mid + 1;
}
ll FuckMinAndMax = 1;
dp[-v[i].second] = max(FuckMinAndMax, seg.query(left, -v[i].second)+1);
seg.update(-v[i].second, dp[-v[i].second]);
//rep(a,0,n)cout << p[a] << " ";
//cout << endl;
//cout << v[i].first << " " << left << " " << seg.query(left, -v[i].second) << endl;
//cout << endl;
}
ll ans = 1;
trav(a, dp)ans = max(ans, a);
cout << ans << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In constructor 'tree::tree(ll, tree::T)':
Main.cpp:36:5: warning: 'tree::n' will be initialized after [-Wreorder]
36 | ll n;
| ^
Main.cpp:35:12: warning: 'std::vector<long long int> tree::s' [-Wreorder]
35 | vector<T> s;
| ^
Main.cpp:37:2: warning: when initialized here [-Wreorder]
37 | tree(ll n=0, T def=unit) : n(n),s(2*n,def){}
| ^~~~
Main.cpp: In function 'int main()':
Main.cpp:68:6: warning: unused variable 'cur' [-Wunused-variable]
68 | ll cur = d;
| ^~~
# | 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... |