Submission #920436

#TimeUsernameProblemLanguageResultExecution timeMemory
920436KiaRezFinancial Report (JOI21_financial)C++17
100 / 100
842 ms45768 KiB
/* IN THE NAME OF GOD */ #include <bits/stdc++.h> // #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") using namespace std; typedef __int128 ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef long double ld; #define F first #define S second #define Mp make_pair #define pb push_back #define pf push_front #define size(x) ((ll)x.size()) #define all(x) (x).begin(),(x).end() #define kill(x) cout << x << '\n', exit(0); #define fuck(x) cout << "(" << #x << " , " << x << ")" << endl #define endl '\n' const int N = 3e5+23, lg = 19; ll Mod = 1e9+7; //998244353; inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;} inline ll poww(ll a, ll b, ll mod=Mod) { ll ans = 1; a=MOD(a, mod); while (b) { if (b & 1) ans = MOD(ans*a, mod); b >>= 1; a = MOD(a*a, mod); } return ans; } struct node { int mx, pref, suff, res, sz; node() { mx = pref = suff = res = sz = 0; } } seg[4*N]; int n, d, a[N], ans; vector<int> comp, vec[N]; node merge(node x, node y) { x.mx = max(x.mx, y.mx); x.res = max({x.res, y.res, x.suff+y.pref}); (x.pref == x.sz) && (x.pref += y.pref); (y.suff == y.sz) && (y.suff += x.suff); x.suff = y.suff; x.sz += y.sz; return x; } void update(int ind, int mx) { if(ind == 0) return; if(ind >= (1<<lg)) { seg[ind].pref = seg[ind].suff = seg[ind].res = 0; seg[ind].mx = mx; } else { seg[ind] = merge(seg[2*ind], seg[2*ind+1]); } update(ind/2, mx); } void build(int ind) { if(ind >= (1<<lg)) { seg[ind].sz = seg[ind].pref = seg[ind].suff = seg[ind].res = 1; return; } build(2*ind); build(2*ind+1); seg[ind] = merge(seg[2*ind], seg[2*ind+1]); } node glob; void query(int x, int ind=1, int lc=1, int rc=(1<<lg)+1) { if(ind >= (1<<lg)) { node tmp = merge(seg[ind], glob); if(tmp.res < d) glob = tmp; return; } int mid = (lc+rc)/2; if(x >= rc) { if(merge(seg[2*ind+1], glob).res < d) { glob = merge(seg[2*ind+1], glob); query(x, 2*ind, lc, mid); } else query(x, 2*ind+1, mid, rc); return; } if(x>=mid) { query(x, 2*ind+1, mid, rc); if(glob.sz == x-mid+1) { query(x, 2*ind, lc, mid); } return; } query(x, 2*ind, lc, mid); } int main () { ios_base::sync_with_stdio(false), cin.tie(0); cin>>n>>d; for(int i=1; i<=n; i++) cin>>a[i], comp.pb(a[i]); sort(all(comp)); comp.resize(unique(all(comp)) - comp.begin()); for(int i=1; i<=n; i++) { int ptr = lower_bound(all(comp), a[i]) - comp.begin() + 1; a[i] = ptr; vec[ptr].pb(i); } build(1); for(int i=1; i<=n; i++) { vector<int> reses; for(auto it : vec[i]) { glob = node(); query(it-1); reses.pb(glob.mx+1); } for(int j=0; j<size(vec[i]); j++) { update(vec[i][j]+(1<<lg)-1, reses[j]); } } cout<<seg[1].mx<<endl; 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...