Submission #401566

# Submission time Handle Problem Language Result Execution time Memory
401566 2021-05-10T13:34:20 Z Pyqe Peru (RMI20_peru) C++14
49 / 100
600 ms 262144 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[400069],sk[400069];
long long dp[400069];

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;
	
	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 2 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 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 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 1 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 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 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 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 1 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 2 ms 468 KB Output is correct
15 Correct 256 ms 44252 KB Output is correct
16 Correct 285 ms 44200 KB Output is correct
17 Correct 271 ms 44232 KB Output is correct
18 Correct 345 ms 44244 KB Output is correct
19 Correct 293 ms 44308 KB Output is correct
20 Correct 270 ms 44232 KB Output is correct
21 Correct 253 ms 44332 KB Output is correct
22 Correct 255 ms 44268 KB Output is correct
23 Correct 249 ms 44360 KB Output is correct
24 Correct 268 ms 44236 KB Output is correct
25 Correct 258 ms 44380 KB Output is correct
26 Correct 267 ms 44168 KB Output is correct
27 Correct 259 ms 44212 KB Output is correct
28 Correct 273 ms 44300 KB Output is correct
29 Correct 281 ms 44260 KB Output is correct
30 Correct 270 ms 44284 KB Output is correct
31 Correct 246 ms 44168 KB Output is correct
32 Correct 271 ms 44200 KB Output is correct
33 Correct 275 ms 44276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 256 ms 44252 KB Output is correct
2 Correct 285 ms 44200 KB Output is correct
3 Correct 271 ms 44232 KB Output is correct
4 Correct 345 ms 44244 KB Output is correct
5 Correct 293 ms 44308 KB Output is correct
6 Correct 270 ms 44232 KB Output is correct
7 Correct 253 ms 44332 KB Output is correct
8 Correct 255 ms 44268 KB Output is correct
9 Correct 249 ms 44360 KB Output is correct
10 Correct 268 ms 44236 KB Output is correct
11 Correct 258 ms 44380 KB Output is correct
12 Correct 267 ms 44168 KB Output is correct
13 Correct 259 ms 44212 KB Output is correct
14 Correct 273 ms 44300 KB Output is correct
15 Correct 281 ms 44260 KB Output is correct
16 Correct 270 ms 44284 KB Output is correct
17 Correct 246 ms 44168 KB Output is correct
18 Correct 271 ms 44200 KB Output is correct
19 Correct 275 ms 44276 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Execution timed out 736 ms 262144 KB Time limit exceeded
35 Halted 0 ms 0 KB -