Submission #851023

#TimeUsernameProblemLanguageResultExecution timeMemory
851023LucaIlieFinancial Report (JOI21_financial)C++17
48 / 100
4021 ms9544 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 3e5; int v[MAX_N], p[MAX_N]; struct SegTree { int segTree[4 * MAX_N]; int lazy[4 * MAX_N]; void propag( int v, bool leaf ) { if ( segTree[v] == 0 ) return; segTree[v] = max( segTree[v], lazy[v] ); if ( !leaf ) { lazy[v * 2 + 1] = max( lazy[v * 2 + 1], lazy[v] ); lazy[v * 2 + 2] = max( lazy[v * 2 + 2], lazy[v] ); } lazy[v] = 0; } void updatePos( int v, int l, int r, int pos, int x ) { propag( v, (l == r) ); if ( l > pos || r < pos ) return; if ( l == r ) { segTree[v] = max( segTree[v], x ); return; } int mid = (l + r) / 2; updatePos( v * 2 + 1, l, mid, pos, x ); updatePos( v * 2 + 2, mid + 1, r, pos, x ); segTree[v] = max( segTree[v * 2 + 1], segTree[v * 2 + 2] ); } void update( int v, int l, int r, int lu, int ru, int x ) { if ( lu > ru ) return; propag( v, (l == r) ); if ( l > ru || r < lu ) return; if ( lu <= l && r <= ru ) { lazy[v] = max( lazy[v], x ); segTree[v] = max( segTree[v], x ); propag( v, (l == r) ); return; } int mid = (l + r) / 2; update( v * 2 + 1, l, mid, lu, ru, x ); update( v * 2 + 2, mid + 1, r, lu, ru, x ); segTree[v] = max( segTree[v * 2 + 1], segTree[v * 2 + 2] ); } int query( int v, int l, int r, int lq, int rq ) { if ( lq > rq ) return 0; propag( v, (l == r)); if ( l > rq || r < lq ) return 0; if ( lq <= l && r <= rq ) return segTree[v]; int mid = (l + r) / 2; return max( query( v * 2 + 1, l, mid, lq, rq ), query( v * 2 + 2, mid + 1, r, lq, rq ) ); } }; SegTree sir; int main() { int n, d; cin >> n >> d; for ( int i = 1; i <= n; i++ ) cin >> v[i], p[i] = i; sort( p + 1, p + 1 + n, []( int i, int j ) { if ( v[i] == v[j] ) return i > j; return v[i] < v[j]; } ); for ( int ii = 1; ii <= n; ii++ ) { int i = p[ii]; int len = sir.query( 0, 1, n, max( 1, i - d ), i - 1 ) + 1; sir.updatePos( 0, 1, n, i, len ); int pos = i; for ( int j = i; j <= n; j++ ) { if ( j - pos > d ) break; if ( v[j] <= v[i] ) pos = j; } sir.update( 0, 1, n, i + 1, pos, len ); } cout << sir.query( 0, 1, n, n, n ); return 0; }
#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...