Submission #483750

# Submission time Handle Problem Language Result Execution time Memory
483750 2021-11-01T02:45:58 Z kawaii Peru (RMI20_peru) C++14
0 / 100
1 ms 468 KB
#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); 
            int c = l2[i - t.second - 1];
            dq.push_back(make_pair(((long long) t.first + max(mx[t.second + 1][c], mx[i - (1 << c) + 1][c])) % mod, i));
            ans = (ans + (long long) dq.back().first * twt[n - i]) % mod; 
        } 
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -