# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
401556 |
2021-05-10T13:27:50 Z |
Pyqe |
Peru (RMI20_peru) |
C++14 |
|
7 ms |
2004 KB |
#include <bits/stdc++.h>
#include "peru.h"
using namespace std;
const int m=23,dv=1e9+7;
long long inf=1e18;
int nn=0,a[2069],sk[2069];
long long dp[2069];
struct segtree
{
int l,r;
long long mn,lz;
segtree *p[2];
void bd(int lh,int rh)
{
l=lh;
r=rh;
mn=0;
lz=0;
if(l<r)
{
int ii,md=(l+r)/2;
for(ii=0;ii<2;ii++)
{
p[ii]=new segtree;
p[ii]->bd(!ii?l:md+1,!ii?md:r);
}
}
}
void blc()
{
int ii;
for(ii=0;ii<2;ii++)
{
p[ii]->mn+=lz;
p[ii]->lz+=lz;
}
lz=0;
}
void ud(int lh,int rh,long long w)
{
if(l>rh||r<lh);
else if(l>=lh&&r<=rh)
{
mn+=w;
lz+=w;
}
else
{
int ii;
blc();
for(ii=0;ii<2;ii++)
{
p[ii]->ud(lh,rh,w);
}
mn=min(p[0]->mn,p[1]->mn);
}
}
long long qr(int lh,int rh)
{
if(l>rh||r<lh)
{
return inf;
}
else if(l>=lh&&r<=rh)
{
return mn;
}
else
{
blc();
return min(p[0]->qr(lh,rh),p[1]->qr(lh,rh));
}
}
}
sg;
int solve(int n,int d,int* aa)
{
int i,ml=1,z=0;
if(n>2000)
{
return 0;
}
sg.bd(1,n);
for(i=1;i<=n;i++)
{
a[i]=aa[i-1];
for(;nn&&a[sk[nn]]<=a[i];nn--)
{
sg.ud(sk[nn-1]+1,sk[nn],a[i]-a[sk[nn]]);
}
nn++;
sk[nn]=i;
sg.ud(i,i,dp[i-1]+a[i]);
dp[i]=sg.qr(max(i-d+1,1),i);
}
for(i=n;i;i--)
{
z=(dp[i]%dv*ml+z)%dv;
ml=(long long)ml*m%dv;
}
return z;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
548 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
548 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Incorrect |
7 ms |
2004 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
2004 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |