Submission #483734

# Submission time Handle Problem Language Result Execution time Memory
483734 2021-11-01T01:57:15 Z kawaii Peru (RMI20_peru) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
//define int long long

long long t, n, m, k, a[2500001], mod = 1e9 + 7, l2[2500001], ans = 0;
long int mx[2500001][22];
deque<pair<long long, 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(long long n, long long k, long long* 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 + 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((t.first + max(mx[t.second][c], mx[i - (1 << c) + 1][c])) % mod, i));
            ans = (ans + dq.back().first * mul(23, n - i)) % mod; 
        }
    }
    return ans;
}

signed main(){ 
    ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(i >= 2) l2[i] = l2[i / 2] + 1;
        mx[i][0] = a[i];
    }
    cout << solve(n, k, a);
}

Compilation message

/usr/bin/ld: /tmp/ccTELxV6.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc6mzKk9.o:peru.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccTELxV6.o: in function `main':
grader.cpp:(.text.startup+0x144): undefined reference to `solve(int, int, int*)'
collect2: error: ld returned 1 exit status