Submission #874955

#TimeUsernameProblemLanguageResultExecution timeMemory
874955efedmrlrFinancial Report (JOI21_financial)C++17
12 / 100
307 ms31660 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int #define MP make_pair #define pb push_back #define REP(i,n) for(int (i) = 0; (i)<(n); (i)++) void fastio() { ios_base::sync_with_stdio(false); cin.tie(NULL); } const int N = 1e5+5; const int MOD = 1e9+7; const int INF = 1e12; const int M = 1e6+5; const long double EPS = 0.00001; int n,m,q,d; vector<int> dp, b; vector<array<int,2> > a; struct SegTree { int sz; vector<int> data, lazy; SegTree(int sz) { this->sz = sz; data.assign(4*(sz + 2), 0); lazy.assign(4*(sz + 2), -1); } void push(int v) { if(lazy[v] == -1) return; data[v*2] = lazy[v]; data[v*2+1] = lazy[v]; lazy[v*2] = lazy[v]; lazy[v*2+1] = lazy[v]; lazy[v] = -1; } void update(int tl, int tr ,int v, int l, int r, int val) { if(tl >= l && tr <= r) { lazy[v] = val; data[v] = val; return; } if(tl > r || tr < l) { return; } push(v); int tm = (tl + tr) >> 1; update(tl, tm, v*2, l, r, val); update(tm + 1, tr, v*2+1, l, r, val); data[v] = max(data[v*2], data[v*2+1]); } void update(int l ,int r, int val) { update(0, sz, 1, l, r, val); } int query(int tl, int tr, int v, int l, int r) { if(tl >= l && tr <= r) return data[v]; if(tl > r || tr < l) { return 0; } push(v); int tm = (tl + tr) >> 1; return max(query(tl, tm, v*2, l, r) , query(tm + 1, tr, v*2+1, l, r)); } int query(int l, int r) { return query(0, sz, 1, l, r); } }; void compress() { sort(a.begin(), a.end()); int last = 0; int cur = 0; for(int i = 0; i<n; i++) { if(a[i][0] == last) { a[i][0] = cur; } else { last = a[i][0]; cur++; a[i][0] = cur; } } b.assign(n+1, 0); for(auto c : a) { b[c[1]] = c[0]; } } signed main() { fastio(); cin>>n>>d; a.resize(n); dp.assign(n + 1, 1); REP(i,n) { cin>>a[i][0]; a[i][1] = i + 1; } compress(); dp[n] = 1; SegTree st(n + 9); st.update(b[n], b[n], dp[n]); for(int i = n - 1; i>=1; i--) { dp[i] = st.query(b[i] + 1, n + 5) + 1; st.update(0, b[i] - 1, 0); st.update(b[i], b[i], dp[i]); } int ans = 0; for(int i = 1; i<=n; i++) { ans = max(ans , dp[i]); } cout<<ans<<"\n"; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:8:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    8 | #define REP(i,n) for(int (i) = 0; (i)<(n); (i)++)
      |                          ^
Main.cpp:98:5: note: in expansion of macro 'REP'
   98 |     REP(i,n) {
      |     ^~~
#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...