# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
886675 | fanwen | Financial Report (JOI21_financial) | C++17 | 397 ms | 22388 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/* author : bo may can 5 */
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define file(name) \
if(fopen(name".inp", "r")) \
freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout);
template < class T, T (*f) (T, T), T (*e) ()>
struct segment_tree {
vector <T> it;
int n;
void update(int u, T p) {
u--;
for(it[u += n] += p; u >>= 1; ) {
it[u] = f(it[u << 1], it[u << 1 | 1]);
}
}
void set(int u, T p) {
u--;
for (it[u += n] = p; u >>= 1; ) {
it[u] = f(it[u << 1], it[u << 1 | 1]);
}
}
T get(int p) {
return it[p += n - 1];
}
T get(int l, int r) {
l--;
T resl = e(), resr = e();
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if(l & 1) resl = f(resl, it[l++]);
if(r & 1) resr = f(it[--r], resr);
}
return f(resl, resr);
}
segment_tree(int n = 0) : n(n), it(n << 1 | 1) {
fill(it.begin(), it.end(), T{});
}
};
int op(int a, int b) { return a > b ? a : b; }
int e() { return 0; }
const int MAX = 3e5 + 5;
int n, D, dp[MAX];
pair <int, int> a[MAX];
set <int> s, diff;
void insert(int u) {
s.insert(u);
auto it = s.find(u);
if(it != s.begin() && next(it) != s.end()) {
if(*next(it) - *prev(it) > D) diff.erase(*next(it));
}
if(next(it) != s.end()) {
int len = *next(it) - u;
if(len > D) diff.insert(*next(it));
}
if(it != s.begin()) {
int len = u - *prev(it);
if(len > D) diff.insert(u);
}
}
void you_make_it(void) {
cin >> n >> D;
for (int i = 1; i <= n; ++i) cin >> a[i].fi, a[i].se = i;
sort(a + 1, a + n + 1, [&] (const pair <int, int> &x, const pair <int, int> &y) {
return x.fi < y.fi || (x.fi == y.fi && x.se > y.se);
});
segment_tree <int, op, e> it(n);
int ans = 0, ptr = 1;
for (int i = 1; i <= n; ++i) {
while(ptr <= n && a[ptr].fi == a[i].fi) {
insert(a[ptr++].se);
}
int d = 0, l = 0;
auto iter = diff.upper_bound(a[i].se);
if(iter == diff.begin()) l = 1;
else l = *prev(iter);
d = it.get(l, a[i].se - 1) + 1;
// cout << l << " " << a[i].se << '\n';
ans = max(ans, d);
it.set(a[i].se, d);
}
cout << ans;
}
signed main() {
#ifdef LOCAL
freopen("TASK.inp", "r", stdin);
freopen("TASK.out", "w", stdout);
#endif
file("financial");
auto start_time = chrono::steady_clock::now();
cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
you_make_it();
auto end_time = chrono::steady_clock::now();
cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl;
return (0 ^ 0);
}
// Dream it. Wish it. Do it.
컴파일 시 표준 에러 (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... |