Submission #431678

#TimeUsernameProblemLanguageResultExecution timeMemory
431678cpp219Financial Report (JOI21_financial)C++14
100 / 100
951 ms27544 KiB
#pragma GCC optimization "O2" #pragma GCC optimization "unroll-loop" #pragma GCC target ("avx2") #include <bits/stdc++.h> #define ll int #define ld long double #define fs first #define sc second using namespace std; const ll N = 3e5 + 9; const ll inf = 1e9 + 7; typedef pair<ll,ll> LL; ll n,D,a[N],dp[N],id[N],ans; ll st[4*N],lab[N]; void upd(ll id,ll l,ll r,ll u,ll val){ if (u < l||r < u) return; if (l == r){ st[id] = val; return; } ll mid = (l + r)/2; upd(id*2,l,mid,u,val); upd(id*2 + 1,mid + 1,r,u,val); st[id] = max(st[id*2],st[id*2 + 1]); } ll Get(ll id,ll l,ll r,ll u,ll v){ if (v < l||r < u) return 0; if (u <= l&&r <= v) return st[id]; ll mid = (l + r)/2; return max(Get(id*2,l,mid,u,v),Get(id*2 + 1,mid + 1,r,u,v)); } bool lf(ll x,ll y){ return a[x] < a[y] || (a[x] == a[y] && x > y); } ll par[N],mn[N]; ll Find(ll u){ if (lab[u] < 0) return u; return lab[u] = Find(lab[u]); } void Union(ll p,ll q){ ll r = Find(p),s = Find(q); if (r == s) return; if (lab[r] > lab[s]) swap(r,s); lab[r] += lab[s]; lab[s] = r; mn[r] = min(mn[r],mn[s]); } set<ll> s; int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define task "tst" if (fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); //freopen(task".out", "w", stdout); } cin>>n>>D; for (ll i = 1;i <= n;i++) cin>>a[i],id[i] = i,mn[i] = i; sort(id + 1,id + n + 1,lf); memset(lab,-1,sizeof(lab)); for (ll i = 1;i <= n;i++){ auto it = s.lower_bound(id[i]); if (it != s.end()){ if (abs(id[i] - *it) <= D) Union(id[i],*it); } if (it != s.begin()){ it--; if (abs(id[i] - *it) <= D) Union(id[i],*it); } s.insert(id[i]); ll L = mn[Find(id[i])]; dp[i] = Get(1,1,n,L,id[i] - 1) + 1; upd(1,1,n,id[i],dp[i]); ans = max(ans,dp[i]); //cout<<id[i]<<" "<<dp[i]<<" "<<L<<" "<<i - 1<<"\n"; } cout<<ans; }

Compilation message (stderr)

Main.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
Main.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
Main.cpp: In function 'int main()':
Main.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...