Submission #483732

# Submission time Handle Problem Language Result Execution time Memory
483732 2021-11-01T01:56:45 Z kawaii Peru (RMI20_peru) C++14
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(){
    if (ifstream("text.txt"))
    {
        freopen("text.txt", "r", stdin);
        #ifdef CHECKING
            freopen(taskname".out", "w", stdout);
        #else
            //\freopen("text.out", "w", stdout);
        #endif //CHECKING
    }
    //freopen("subsubset.inp", "r", stdin);
    //freopen("subsubset.out", "w", stdout);
    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

peru.cpp: In function 'int main()':
peru.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen("text.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccHm26zQ.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccB1lp6N.o:peru.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccHm26zQ.o: in function `main':
grader.cpp:(.text.startup+0x144): undefined reference to `solve(int, int, int*)'
collect2: error: ld returned 1 exit status