Submission #855874

#TimeUsernameProblemLanguageResultExecution timeMemory
855874TimDeePeru (RMI20_peru)C++17
49 / 100
934 ms126408 KiB
// Esti <3 //\ šťastia pre nás :) // you're already the best // _ // ^ ^ // // >(O_O)<___// // \ __ __ \ // \\ \\ \\\\ #include <bits/stdc++.h> using namespace std; //#pragma GCC optimize("O3","unroll-loops") //#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #pragma GCC optimize("O3") #pragma GCC target("popcnt") using ll = long long; #define int long long #define forn(i,n) for(int i=0; i<(n); ++i) #define pb push_back #define pi pair<int,int> #define f first #define s second #define vii(a,n) vector<int> a(n); forn(i,n) cin>>a[i]; #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll inf = 1e18; const ll mod = 1e9+7;//998244853; // \ \ :smiling_face_with_3_hearts: :smiling_face_with_3_hearts: :smiling_face_with_3_hearts: //vidime sa veľmi skoro, moje slnko const int N=25e5+5; int dp[N]; int t[2*N]; int lazy[2*N]; void updup(int v) { v>>=1; while(v) { t[v]=min(t[v<<1],t[(v<<1)|1])+lazy[v]; v>>=1; } } void updv(int v, int x) { t[v]+=x; lazy[v]+=x; } void push(int v) { for (int i=22; i; --i) { int u = v>>i; if ((u) && lazy[u]) { updv(u<<1,lazy[u]); updv((u<<1)|1,lazy[u]); lazy[u]=0; } } } void Set(int i) { i+=N; t[i]=dp[i-N]; updup(i); } void upd(int l, int r, int x) { l+=N, r+=N; int lq=l, rq=r; while (l<r) { if (l&1) { updv(l++,x); } if (r&1) { updv(--r,x); } l>>=1, r>>=1; } updup(lq); updup(rq-1); } int query(int l, int r) { l+=N, r+=N; push(l); push(r-1); int ans = inf; while (l<r) { if (l&1) { ans=min(ans,t[l++]); } if (r&1) { ans=min(ans,t[--r]); } l>>=1; r>>=1; } return ans; } int32_t solve(int32_t n, int32_t k, int32_t* a) { if (n==1) return a[0]%mod; forn(i,n+1) dp[i]=inf; forn(i,2*N) t[i]=inf; dp[0]=0; Set(0); vector<pi> st={ {0,inf} }; for (int i=1; i<=n; ++i) { while (st.back().s <= a[i-1]) { int r = st.back().f; int x = st.back().s; st.pop_back(); int l = st.back().f; upd(l,r,-x); } int l = st.back().f; int r = i; upd(l,r,a[i-1]); st.pb({r,a[i-1]}); int x = query(max(i-k,0ll),i); dp[i] = x; Set(i); } int ans=0, p=1; for (int i=n; i; --i) { dp[i]%=mod; ans=(ans+p*dp[i])%mod; p=(p*23)%mod; } return ans; }

Compilation message (stderr)

peru.cpp:3:1: warning: multi-line comment [-Wcomment]
    3 | //\
      | ^
peru.cpp:9:1: warning: multi-line comment [-Wcomment]
    9 | //   \ __ __  \
      | ^
peru.cpp:36:1: warning: multi-line comment [-Wcomment]
   36 | // \
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...