Submission #874951

#TimeUsernameProblemLanguageResultExecution timeMemory
874951efedmrlrFinancial Report (JOI21_financial)C++17
5 / 100
186 ms22176 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; SegTree(int sz) { this->sz = sz; data.assign(4*(sz + 2), 0); } void update(int tl, int tr ,int v, int ind, int val) { if(tl == tr) { data[v] = max(data[v], val); return; } int tm = (tl + tr) >> 1; if(ind <= tm) { update(tl, tm, v*2, ind, val); } else { update(tm + 1, tr, v*2+1, ind, val); } data[v] = max(data[v*2], data[v*2+1]); } void update(int ind ,int val) { update(0, sz, 1, ind ,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; } 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() { cin>>n>>d; a.resize(n); dp.assign(n + 1, 1); REP(i,n) { cin>>a[i][0]; a[i][1] = i + 1; } compress(); SegTree st(n+5); for(int i = 1; i<=n; i++) { dp[i] = st.query(0, b[i] - 1) + 1; st.update(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:86:5: note: in expansion of macro 'REP'
   86 |     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...