Submission #469621

#TimeUsernameProblemLanguageResultExecution timeMemory
469621Jarif_RahmanFinancial Report (JOI21_financial)C++17
48 / 100
4069 ms41412 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; struct segtree{ struct node{ int mx; node(){ mx = 0; } node(ll x){ mx = x; } node operator+(node a){ node rt; rt.mx = max(mx, a.mx); return rt; } }; int k; vector<node> v; segtree(int n){ k = 1; while(k < n) k*=2; k*=2; v.resize(k, node()); } void upd(int in, ll x){ in+=k/2; v[in] = node(x); in/=2; while(in > 0){ v[in] = v[2*in]+v[2*in+1]; in/=2; } } ll smx(int l, int r, int nd, int a, int b){ if(b < l || a > r) return 0; if(a >= l && b <= r) return v[nd].mx; int c = (a+b)/2; return max(smx(l, r, 2*nd, a, c), smx(l, r, 2*nd+1, c+1, b)); } ll smx(int l, int r){ return smx(l, r, 1, 0, k/2-1); } }; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, d; cin >> n >> d; vector<int> v(n); for(int &x: v) cin >> x; vector<int> cmpr; map<int, int> mp; cmpr = v; sort(cmpr.begin(), cmpr.end()); for(int i = 0; i < n; i++) mp[cmpr[i]] = i; for(int &x: v) x = mp[x]; vector<int> lim(n); for(int i = 0; i < n; i++){ lim[i] = 0; int cnt = 0; for(int j = i-1; j >= 0; j--){ if(v[j] >= v[i]) cnt++; else cnt = 0; if(cnt == d){ lim[i] = j; break; } } } segtree seg(n); vector<vector<int>> sth(n); for(int i = n-1; i >= 0; i--) sth[v[i]].pb(i); for(int i = 0; i < n; i++){ for(int j = 0; j < sth[i].size(); j++){ int x = seg.smx(lim[sth[i][j]], sth[i][j]-1)+1; seg.upd(sth[i][j], seg.smx(lim[sth[i][j]], sth[i][j]-1)+1); } } cout << seg.smx(0, n-1) << "\n"; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:85:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |         for(int j = 0; j < sth[i].size(); j++){
      |                        ~~^~~~~~~~~~~~~~~
Main.cpp:86:17: warning: unused variable 'x' [-Wunused-variable]
   86 |             int x = seg.smx(lim[sth[i][j]], sth[i][j]-1)+1;
      |                 ^
#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...