Submission #859726

#TimeUsernameProblemLanguageResultExecution timeMemory
859726activedeltorrePeru (RMI20_peru)C++14
0 / 100
1 ms2392 KiB
#include <iostream> #include <queue> #include "peru.h" using namespace std; priority_queue<pair<long long,long long> >pq; priority_queue<pair<long long,long long> >pq2; long long dp[5000005]; int solve(int n, int k, int* v) { long long maxim=0,a,b,i; for(i=0;i<k;i++) { maxim=max(maxim,1LL*v[i]); dp[i]=maxim; pq.push({v[i],i}); pq2.push({-maxim,i}); } for(i=k;i<n+k-1;i++) { pq.push({v[i],i}); while(pq.top().second<=i-k) { pq.pop(); } while(pq2.top().second<i-k) { pq2.pop(); } a=pq.top().first; b=pq2.top().first; dp[i]=pq.top().first-pq2.top().first; pq2.push({-dp[i],i}); } dp[n+k-1]=1e17; for(i=n+k-2;i>=0;i--) { dp[i]=min(dp[i],dp[i+1]); } long long suma=0,mod=1000000007; for(i=0;i<n;i++) { suma=(suma*23+dp[i])%mod; } return suma; } /* #include<iostream> //#include "peru.h" using namespace std; static int s[2500005]; static int n, k; int main(){ cin>> n >> k; for(int i = 0; i < n; i++){ cin>> s[i]; } int ans = solve(n, k, s); cout<< ans <<"\n"; return 0; } */

Compilation message (stderr)

peru.cpp: In function 'int solve(int, int, int*)':
peru.cpp:11:23: warning: variable 'a' set but not used [-Wunused-but-set-variable]
   11 |     long long maxim=0,a,b,i;
      |                       ^
peru.cpp:11:25: warning: variable 'b' set but not used [-Wunused-but-set-variable]
   11 |     long long maxim=0,a,b,i;
      |                         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...