Submission #881911

#TimeUsernameProblemLanguageResultExecution timeMemory
881911deadeye0Financial Report (JOI21_financial)C++17
19 / 100
619 ms62944 KiB
#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)

Main.cpp: In constructor 'node::node(int, int)':
Main.cpp:23:20: warning: 'node::e' will be initialized after [-Wreorder]
   23 |     int val, s, m, e, lazyadd;
      |                    ^
Main.cpp:23:17: warning:   'int node::m' [-Wreorder]
   23 |     int val, s, m, e, lazyadd;
      |                 ^
Main.cpp:25:5: warning:   when initialized here [-Wreorder]
   25 |     node(int _s, int _e): s(_s), e(_e), m((_s+_e)/2), val(0), lazyadd(0), upd(false), l(NULL), r(NULL) {
      |     ^~~~
Main.cpp:23:17: warning: 'node::m' will be initialized after [-Wreorder]
   23 |     int val, s, m, e, lazyadd;
      |                 ^
Main.cpp:23:9: warning:   'int node::val' [-Wreorder]
   23 |     int val, s, m, e, lazyadd;
      |         ^~~
Main.cpp:25:5: warning:   when initialized here [-Wreorder]
   25 |     node(int _s, int _e): s(_s), e(_e), m((_s+_e)/2), val(0), lazyadd(0), upd(false), l(NULL), r(NULL) {
      |     ^~~~
Main.cpp:24:10: warning: 'node::upd' will be initialized after [-Wreorder]
   24 |     bool upd;
      |          ^~~
Main.cpp:22:11: warning:   'node* node::l' [-Wreorder]
   22 |     node *l, *r;
      |           ^
Main.cpp:25:5: warning:   when initialized here [-Wreorder]
   25 |     node(int _s, int _e): s(_s), e(_e), m((_s+_e)/2), val(0), lazyadd(0), upd(false), l(NULL), r(NULL) {
      |     ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...