# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
859781 |
2023-10-10T15:46:51 Z |
activedeltorre |
Peru (RMI20_peru) |
C++14 |
|
600 ms |
106556 KB |
#include <iostream>
#include <queue>
#include <stack>
#include "peru.h"
#pragma GCC optimize(" unroll-loops")
#pragma GCC optimization("Ofast")
using namespace std;
long long lazy[8300005];
long long va[8300005];
int vec[5000005];
//ifstream cin("a.in");
//ofstream cout("a.out");
stack<pair<long long,int> >st;
void push_lazy(int node,int st,int dr)
{
va[node]+=lazy[node];
if(st!=dr)
{
lazy[node*2]+=lazy[node];
lazy[node*2+1]+=lazy[node];
}
lazy[node]=0;
}
void update(int node,int st,int dr,int qst,int qdr,long long val)
{
push_lazy(node,st,dr);
if(st>dr || st>qdr || qst>dr || qst>qdr)
return ;
if(qst<=st && dr<=qdr)
{
lazy[node]=val;
push_lazy(node,st,dr);
return ;
}
int mij=(st+dr)/2;
update(node*2,st,mij,qst,qdr,val);
update(node*2+1,mij+1,dr,qst,qdr,val);
va[node]=min(va[node*2],va[node*2+1]);
}
long long querry(int node,int st,int dr,int qst,int qdr)
{
push_lazy(node,st,dr);
if(st>dr || st>qdr || qst>dr || qst>qdr)
return 1e18;
if(qst<=st && dr<=qdr)
return va[node];
int mij=(st+dr)/2;
return min(querry(node*2,st,mij,qst,qdr),querry(node*2+1,mij+1,dr,qst,qdr));
}
long long dp[2500005];
int solve(int n, int k, int* v)
{
int a,b,i,poz;
long long val;
for(i=1;i<=n;i++)
{
vec[i]=v[i-1];
}
st.push({1e18,-1});
for(i=1;i<=n;i++)
{
a=vec[i];
while(a>st.top().first)
{
val=st.top().first;
poz=st.top().second;
st.pop();
update(1,0,n,st.top().second,poz-1,-val);
}
update(1,0,n,st.top().second,i-1,a);
st.push({a,i});
dp[i]=querry(1,0,n,max(0,i-k),i-1);
update(1,0,n,i,i,dp[i]);
}
int maxim=0;
dp[n+1]=1e18;
for(i=n;i>=n-k+1;i--)
{
dp[n+1]=min(dp[n+1],dp[i]+maxim);
maxim=max(maxim,vec[i]);
}
dp[n+2]=1e18;
for(i=n;i>=1;i--)
{
dp[i]=min(dp[i],dp[i+1]);
}
long long suma=0,mod=1000000007;
for(i=1;i<=n;i++)
{
suma=(suma*23+dp[i])%mod;
// cout<<dp[i]<<" ";
}
return suma;
}
/*
//#include "peru.h"
using namespace std;
static int s[2500005];
static int n, k;
signed 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
peru.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
6 | #pragma GCC optimization("Ofast")
|
peru.cpp:5:37: warning: bad option '-f unroll-loops' to pragma 'optimize' [-Wpragmas]
5 | #pragma GCC optimize(" unroll-loops")
| ^
peru.cpp:14:38: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
14 | void push_lazy(int node,int st,int dr)
| ^
peru.cpp:24:65: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
24 | void update(int node,int st,int dr,int qst,int qdr,long long val)
| ^
peru.cpp:40:56: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
40 | long long querry(int node,int st,int dr,int qst,int qdr)
| ^
peru.cpp:51:31: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
51 | int solve(int n, int k, int* v)
| ^
peru.cpp: In function 'int solve(int, int, int*)':
peru.cpp:53:11: warning: unused variable 'b' [-Wunused-variable]
53 | int a,b,i,poz;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8536 KB |
Output is correct |
2 |
Correct |
2 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
8536 KB |
Output is correct |
5 |
Correct |
3 ms |
8540 KB |
Output is correct |
6 |
Correct |
2 ms |
8536 KB |
Output is correct |
7 |
Correct |
3 ms |
8540 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
8540 KB |
Output is correct |
11 |
Correct |
3 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
3 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8536 KB |
Output is correct |
2 |
Correct |
2 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
8536 KB |
Output is correct |
5 |
Correct |
3 ms |
8540 KB |
Output is correct |
6 |
Correct |
2 ms |
8536 KB |
Output is correct |
7 |
Correct |
3 ms |
8540 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
8540 KB |
Output is correct |
11 |
Correct |
3 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
3 ms |
8540 KB |
Output is correct |
15 |
Correct |
428 ms |
32124 KB |
Output is correct |
16 |
Correct |
387 ms |
32340 KB |
Output is correct |
17 |
Correct |
387 ms |
32632 KB |
Output is correct |
18 |
Correct |
400 ms |
32084 KB |
Output is correct |
19 |
Correct |
413 ms |
32648 KB |
Output is correct |
20 |
Correct |
402 ms |
32140 KB |
Output is correct |
21 |
Correct |
395 ms |
32588 KB |
Output is correct |
22 |
Correct |
388 ms |
32596 KB |
Output is correct |
23 |
Correct |
398 ms |
32616 KB |
Output is correct |
24 |
Correct |
385 ms |
32332 KB |
Output is correct |
25 |
Correct |
396 ms |
32580 KB |
Output is correct |
26 |
Correct |
392 ms |
32484 KB |
Output is correct |
27 |
Correct |
417 ms |
32340 KB |
Output is correct |
28 |
Correct |
397 ms |
32508 KB |
Output is correct |
29 |
Correct |
393 ms |
32300 KB |
Output is correct |
30 |
Correct |
394 ms |
32596 KB |
Output is correct |
31 |
Correct |
380 ms |
32340 KB |
Output is correct |
32 |
Correct |
395 ms |
32392 KB |
Output is correct |
33 |
Correct |
388 ms |
32340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
428 ms |
32124 KB |
Output is correct |
2 |
Correct |
387 ms |
32340 KB |
Output is correct |
3 |
Correct |
387 ms |
32632 KB |
Output is correct |
4 |
Correct |
400 ms |
32084 KB |
Output is correct |
5 |
Correct |
413 ms |
32648 KB |
Output is correct |
6 |
Correct |
402 ms |
32140 KB |
Output is correct |
7 |
Correct |
395 ms |
32588 KB |
Output is correct |
8 |
Correct |
388 ms |
32596 KB |
Output is correct |
9 |
Correct |
398 ms |
32616 KB |
Output is correct |
10 |
Correct |
385 ms |
32332 KB |
Output is correct |
11 |
Correct |
396 ms |
32580 KB |
Output is correct |
12 |
Correct |
392 ms |
32484 KB |
Output is correct |
13 |
Correct |
417 ms |
32340 KB |
Output is correct |
14 |
Correct |
397 ms |
32508 KB |
Output is correct |
15 |
Correct |
393 ms |
32300 KB |
Output is correct |
16 |
Correct |
394 ms |
32596 KB |
Output is correct |
17 |
Correct |
380 ms |
32340 KB |
Output is correct |
18 |
Correct |
395 ms |
32392 KB |
Output is correct |
19 |
Correct |
388 ms |
32340 KB |
Output is correct |
20 |
Correct |
2 ms |
8536 KB |
Output is correct |
21 |
Correct |
2 ms |
8540 KB |
Output is correct |
22 |
Correct |
2 ms |
8540 KB |
Output is correct |
23 |
Correct |
2 ms |
8536 KB |
Output is correct |
24 |
Correct |
3 ms |
8540 KB |
Output is correct |
25 |
Correct |
2 ms |
8536 KB |
Output is correct |
26 |
Correct |
3 ms |
8540 KB |
Output is correct |
27 |
Correct |
2 ms |
8540 KB |
Output is correct |
28 |
Correct |
2 ms |
8540 KB |
Output is correct |
29 |
Correct |
2 ms |
8540 KB |
Output is correct |
30 |
Correct |
3 ms |
8540 KB |
Output is correct |
31 |
Correct |
2 ms |
8540 KB |
Output is correct |
32 |
Correct |
2 ms |
8540 KB |
Output is correct |
33 |
Correct |
3 ms |
8540 KB |
Output is correct |
34 |
Execution timed out |
1032 ms |
106556 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |