#include <bits/stdc++.h>
using namespace std;
//define int long long
long long mod = 1e9 + 7, ans = 0;
int n, m, k, a[2500001], l2[2500001], mx[2500001][22];
deque<pair<int, int> > dq;
long long mul(long long x, long long y){
if(y == 0) return 1;
long long ans = mul(x, y / 2);
if(y % 2 == 0) return (ans * ans) % mod;
else return (((ans * ans) % mod) * x) % mod;
}
int solve(int n, int k, int* a){
for(int i = 0; i <= n; i++){
for(int j = 1; (1 << j) <= 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(dq.size() == 0){
dq.push_back(make_pair(a[i], i));
ans = (ans + (long long) a[i] * mul(23, n - i)) % mod;
}
else{
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);
while(dq.size() > 0 && i - dq.front().second > k) dq.pop_front();
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 * mul(23, n - i)) % mod;
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |