Submission #401542

# Submission time Handle Problem Language Result Execution time Memory
401542 2021-05-10T13:19:39 Z Pyqe Peru (RMI20_peru) C++14
49 / 100
303 ms 262144 KB
#include <bits/stdc++.h>
#include "peru.h"

using namespace std;

const long long m=23,dv=1e9+7,inf=1e18;
long long nn=0,a[2500069],dp[2500069],sk[2500069];

struct segtree
{
	long long l,r,mn,lz;
	segtree *p[2];
	
	void bd(long long lh,long long rh)
	{
		l=lh;
		r=rh;
		mn=0;
		lz=0;
		if(l<r)
		{
			long long 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()
	{
		long long ii;
		
		for(ii=0;ii<2;ii++)
		{
			p[ii]->mn+=lz;
			p[ii]->lz+=lz;
		}
		lz=0;
	}
	void ud(long long lh,long long rh,long long w)
	{
		if(l>rh||r<lh);
		else if(l>=lh&&r<=rh)
		{
			mn+=w;
			lz+=w;
		}
		else
		{
			long long 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(long long lh,long long 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)
{
	long long 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,1ll),i);
	}
	for(i=n;i;i--)
	{
		z=(z+dp[i]%dv*ml)%dv;
		ml=ml*m%dv;
	}
	return z;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 262 ms 58348 KB Output is correct
16 Correct 261 ms 58352 KB Output is correct
17 Correct 269 ms 58408 KB Output is correct
18 Correct 283 ms 58316 KB Output is correct
19 Correct 286 ms 58288 KB Output is correct
20 Correct 303 ms 58300 KB Output is correct
21 Correct 258 ms 58432 KB Output is correct
22 Correct 283 ms 58540 KB Output is correct
23 Correct 269 ms 58460 KB Output is correct
24 Correct 260 ms 58536 KB Output is correct
25 Correct 254 ms 58640 KB Output is correct
26 Correct 254 ms 58392 KB Output is correct
27 Correct 271 ms 58408 KB Output is correct
28 Correct 264 ms 58344 KB Output is correct
29 Correct 266 ms 58388 KB Output is correct
30 Correct 259 ms 58412 KB Output is correct
31 Correct 270 ms 58312 KB Output is correct
32 Correct 266 ms 58368 KB Output is correct
33 Correct 275 ms 58512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 262 ms 58348 KB Output is correct
2 Correct 261 ms 58352 KB Output is correct
3 Correct 269 ms 58408 KB Output is correct
4 Correct 283 ms 58316 KB Output is correct
5 Correct 286 ms 58288 KB Output is correct
6 Correct 303 ms 58300 KB Output is correct
7 Correct 258 ms 58432 KB Output is correct
8 Correct 283 ms 58540 KB Output is correct
9 Correct 269 ms 58460 KB Output is correct
10 Correct 260 ms 58536 KB Output is correct
11 Correct 254 ms 58640 KB Output is correct
12 Correct 254 ms 58392 KB Output is correct
13 Correct 271 ms 58408 KB Output is correct
14 Correct 264 ms 58344 KB Output is correct
15 Correct 266 ms 58388 KB Output is correct
16 Correct 259 ms 58412 KB Output is correct
17 Correct 270 ms 58312 KB Output is correct
18 Correct 266 ms 58368 KB Output is correct
19 Correct 275 ms 58512 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 2 ms 596 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 2 ms 596 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
30 Correct 2 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 2 ms 596 KB Output is correct
33 Correct 2 ms 596 KB Output is correct
34 Runtime error 223 ms 262144 KB Execution killed with signal 9
35 Halted 0 ms 0 KB -