QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#116890#149. Perucsy2005#0 0ms0kbC++142.8kb2023-06-30 09:55:282024-09-10 16:35:30

Judging History

你现在查看的是最新测评结果

  • [2024-09-10 16:35:30]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-05-31 18:33:50]
  • 评测
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-30 09:55:28]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<cassert>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(((long long)(n))-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();++itr)
#define pb push_back
#define mk make_pair
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define spln(i,n) (i==n?'\n':' ')
#define fac_init(n){fac[0]=fac[1]=inv[1]=fi[0]=fi[1]=1;fz(i,2,n){fac[i]=1ll*fac[i-1]*i%mod;inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;fi[i]=1ll*fi[i-1]*inv[i]%mod;}}
using namespace std;
typedef long long i64;
typedef long double f80;
typedef unsigned int u32;
typedef unsigned long long u64;
//typedef __int128 i128;
//typedef unsigned __int128 u128;
const int mod=1e9+7;
int n,k,i,j,a[2500005];
i64 f[2500005];
struct deque
{
	i64 qx[5000005];int ql,qr;
	void init(){ql=2500001;qr=2500000;}
	void push_back(int x)
	{
		qx[++qr]=x;
	}
	void push_front(int x)
	{
		qx[--ql]=x;
	}
	void pop_back()
	{
		qr--;
	}
	void pop_front()
	{
		ql++;
	}
	int query()
	{
		i64 s=0x3f3f3f3f3f3f3f3fll;int i;
		fz(i,ql,qr) s=min(s,qx[i]);
		return s;
	}
}dq;
int qx[2500005],ql,qr;
int hd[2500005],tl[2500005];
i64 hdv[2500005],tlv[2500005];
int pre[2500005],suf[2500005];i64 dlt[2500005];
int solve(int nn,int kk,int *aa)
{
	n=nn;k=kk;fz1(i,n)a[i]=aa[i-1];
	ql=1;qr=0;dq.init();
	fz1(i,n){
		hd[i]=tl[i]=i;hdv[i]=tlv[i]=a[i]+f[i-1];
		while(ql<=qr&&a[qx[qr]]<=a[i]){
			hdv[qx[qr]]+=a[i]-a[qx[qr]];
			tlv[qx[qr]]+=a[i]-a[qx[qr]];
			while(tl[qx[qr]]&&tlv[qx[qr]]>=hdv[i]){
				tlv[qx[qr]]-=dlt[tl[qx[qr]]];
				suf[tl[qx[qr]]=pre[tl[qx[qr]]]]=0;
			}
			if(tl[qx[qr]]){
				suf[tl[qx[qr]]]=hd[i];pre[hd[i]]=tl[qx[qr]];
				dlt[hd[i]]=hdv[i]-tlv[qx[qr]];hdv[i]=hdv[qx[qr]];hd[i]=hd[qx[qr]];
			}
			dq.pop_back();qr--;
		}
		qx[++qr]=i;dq.push_back(hdv[i]);
		while(ql<=qr&&qx[ql]<=i-k) ql++,dq.pop_front();
		assert(ql<=qr);
		while(hd[qx[ql]]<=i-k){
			dq.pop_front();
			hd[qx[ql]]=suf[hd[qx[ql]]];hdv[qx[ql]]+=dlt[hd[qx[ql]]];
			dq.push_front(hdv[qx[ql]]);
		}
		f[i]=dq.query();
	}
//	fz1(i,n)cerr<<f[i]<<' ';cerr<<endl;
	int ans=0;fz1(i,n)ans=(23ll*ans+f[i])%mod;return ans;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

input:

2000 170
1054018657 1037445664 1011691297 1009972317 1006506677 1002579733 999792775 999477541 975467893 970302369 968173111 957735623 953086083 938540451 932313113 930563895 924682633 917831575 913506401 908739591 905368525 899452913 894354220 890127447 885923007 583391543 880642788 878397752 87822...

output:


result:


Subtask #2:

score: 0
Time Limit Exceeded

Test #15:

score: 0
Time Limit Exceeded

input:

400000 1000
1999989721 1999987224 1999984551 1999977673 1999977545 1999976801 1999975837 1999972607 1999956301 1999952801 1999942489 1999940593 1999940337 1999936353 1999936273 1999926073 1999925513 1999922980 1999918301 1999912501 1999909301 1999906125 1999902913 1999895622 1999893617 1999885490 19...

output:


result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #34:

score: 0
Time Limit Exceeded

input:

2500000 2000
1073315871 1073250349 1072791751 1072104046 1072071097 1071841833 1071809381 1071710686 1071580105 1071482003 1071383725 1071154701 1070499431 1070335288 1070334157 1069943617 1069681476 1069584279 1069581771 1069322519 1069189353 1069125955 1068832186 1068797487 1068662939 1068565681 1...

output:


result: