# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
881911 | deadeye0 | Financial Report (JOI21_financial) | C++17 | 619 ms | 62944 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define si second
#define ar array
#define pb push_back
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;
typedef vector<int> vi;
template<typename T> bool chmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
const int N = 300010;
int n, d, ans;
int a[N], dp[N];
struct node {
node *l, *r;
int val, s, m, e, lazyadd;
bool upd;
node(int _s, int _e): s(_s), e(_e), m((_s+_e)/2), val(0), lazyadd(0), upd(false), l(NULL), r(NULL) {
if (s != e) l = new node(s, m), r = new node(m+1, e);
}
int value() {
if (upd) {
val = lazyadd;
upd = false;
if (s == e) return val;
l->lazyadd = lazyadd;
r->lazyadd = lazyadd;
r->upd = true, l->upd = true;
}
return val;
}
void set(int x, int y, int v) {
if (s == x && e == y) lazyadd = v, upd = true;
else {
if (x > m) r->set(x, y, v);
else if (y <= m) l->set(x, y, v);
else l->set(x, m, v), r->set(m+1, y, v);
val = max(l->value(), r->value());
}
}
int query(int x, int y) {
value();
if (s == x && e == y) return value();
if (x > m) return r->query(x, y);
if (y <= m) return l->query(x, y);
return max(l->query(x, m),r->query(m+1, y));
}
} *st, *active;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin.exceptions(ios::badbit|ios::failbit);
cin >> n >> d;
vector<int> temp(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
temp[i] = a[i];
}
sort(temp.begin(), temp.end());
temp.resize(unique(temp.begin(), temp.end()) - temp.begin());
for (int i = 0; i < n; ++i) {
a[i] = lower_bound(temp.begin(), temp.end(), a[i]) - temp.begin();
}
st = new node(0, n);
active = new node(0, n);
for (int i = 0; i < n; ++i) {
if (i - d - 1 >= 0) {
if (active->query(a[i - d - 1], a[i - d - 1]) < i - d) {
st->set(a[i - d - 1], a[i - d - 1], 0);
}
}
chmax(dp[a[i]], 1);
if (a[i] > 0) chmax(dp[a[i]], st->query(0, a[i] - 1) + 1);
if (st->query(a[i], a[i]) < dp[a[i]]) {
st->set(a[i], a[i], dp[a[i]]);
}
active->set(a[i], n, i);
chmax(ans, dp[a[i]]);
}
cout << ans;
return 0;
}
Compilation message (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... |