Submission #483748

#TimeUsernameProblemLanguageResultExecution timeMemory
483748kawaiiPeru (RMI20_peru)C++14
0 / 100
0 ms468 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,avx2,fma,bmi,bmi2") #include <bits/stdc++.h> using namespace std; //define int long long long long mod = 1e9 + 7, ans = 0; int n, m, k, a[2500005], l2[2500005], mx[2500005][22], twt[2500005]; deque<pair<int, int> > dq; int solve(int n, int k, int* a){ twt[0] = 1; for(int i = 1; i <= n; i++){ if(i >= 2) l2[i] = l2[i / 2] + 1; mx[i][0] = a[i]; twt[i] = ((long long) twt[i - 1] * 23) % mod; } for(int i = 0; i <= n; i++){ for(int j = 1; i + (1 << (j - 1)) <= n; j++){ mx[i][j] = max(mx[i][j - 1], mx[i + (1 << (j - 1))][j - 1]); } } dq.push_back(make_pair(0, 0)); for(int i = 1; i <= n; i++){ if(ans >= mod) cout << ans <<" "; if(dq.size() == 0){ dq.push_back(make_pair(a[i], i)); ans = (ans + (long long) a[i] * twt[n - i]) % mod; } else{ while(dq.size() > 0 && i - dq.front().second > k) dq.pop_front(); int q = dq.front().first; pair<int, int> t; while(dq.size() > 0 && dq.front().first == q){ t = dq.front(); dq.pop_front(); } dq.push_front(t); t = dq.front(); int c = l2[i - t.second]; dq.push_back(make_pair(((long long) t.first + max(mx[t.second][c], mx[i - (1 << c) + 1][c])) % mod, i)); ans = (ans + (long long) dq.back().first * twt[n - i]) % mod; } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...