Submission #661604

#TimeUsernameProblemLanguageResultExecution timeMemory
661604victor_gaoFinancial Report (JOI21_financial)C++17
48 / 100
911 ms534148 KiB
//#pragma GCC optimize("Ofast,unroll-loops,O3") //#pragma GCC optimize("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma,tune=native") #include<bits/stdc++.h> //#include<bits/extc++.h> //#pragma pack(1) #define fast ios::sync_with_stdio(0); cin.tie(0); #define int long long #define pii pair<int,int> #define x first #define y second #define N 7015 using namespace std; //using namespace __gnu_pbds; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //typedef tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> order_multiset; //typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> order_set; struct lisan{ vector<int>vt; void in(int x){ vt.push_back(x); } void build(){ sort(vt.begin(),vt.end()); vt.resize(unique(vt.begin(),vt.end())-vt.begin()); } int idx(int x){ return upper_bound(vt.begin(),vt.end(),x)-vt.begin(); } }uni; int dp[N][N],n,d,a[N]; deque<int>dq[N]; signed main(){ fast cin>>n>>d; for (int i=1;i<=n;i++){ cin>>a[i]; uni.in(a[i]); } uni.build(); for (int i=1;i<=n;i++) a[i]=uni.idx(a[i]); int mx=0; for (int i=1;i<=n;i++){ for (int j=1;j<=uni.vt.size();j++){ while (!dq[j].empty()&&i-dq[j].front()>d) dq[j].pop_front(); if (j>=a[i]){ if (!dq[j].empty()) dp[i][j]=max(dp[dq[j].front()][j],dp[i][j]); else dp[i][j]=max(1LL,dp[i][j]); while (!dq[j].empty()&&dp[dq[j].back()][j]<=dp[i][j]) dq[j].pop_back(); dq[j].push_back(i); } else { if (!dq[j].empty()) dp[i][a[i]]=max(dp[dq[j].front()][j]+1,dp[i][a[i]]); else dp[i][a[i]]=max(1LL,dp[i][a[i]]); while (!dq[a[i]].empty()&&dp[dq[a[i]].back()][a[i]]<=dp[i][a[i]]) dq[a[i]].pop_back(); dq[a[i]].push_back(i); } mx=max(mx,dp[i][j]); } /* for (int j=1;j<=uni.vt.size();j++){ cout<<j<<" -> "; for (auto k:dq[j]) cout<<k<<","<<dp[k][j]<<" "; cout<<'\n'; } cout<<'\n'; */ } /* for (int i=1;i<=n;i++){ for (int j=1;j<=uni.vt.size();j++) cout<<dp[i][j]<<" "; cout<<'\n'; } */ cout<<mx<<'\n'; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:40:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for (int j=1;j<=uni.vt.size();j++){
      |                      ~^~~~~~~~~~~~~~~
#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...