QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#357735#3300. Cactus CompetitionD_F_SWA 3ms24276kbC++142.3kb2024-03-19 10:13:442024-03-19 10:13:45

Judging History

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

  • [2024-03-19 10:13:45]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:24276kb
  • [2024-03-19 10:13:44]
  • 提交

answer

#include<bits/stdc++.h>
#define inl inline
using namespace std;
const int N=2e5+5,V=1e9+1,IB=1<<21; char IN[IB],*IS=IN+IB,*IT=IS;
#define getchar() (IS==IT&&(fread(IS=IN,1,IB,stdin)),*IS++)
struct D {int lx,rx,ly,ry; }d[N*5];
struct C {int l,r,v; }; vector<C> c[N];
struct TR {int v,c,t; }tr[N*4];
int n,m,dc,ab=-V,ib=V,id,a[N],b[N],sb[N],bi[N],sa[18][N]; long long an;
inl int Read()
{
	int s=0,f=1; char c; while(!isdigit(c=getchar())) c=='-'&&(f=-1);
	for(;isdigit(c);c=getchar()) s=s*10+c-'0'; return s*f;
}
inl int Ask(int l,int r) {int k=__lg(r-l+1); return max(sa[k][l],sa[k][r-(1<<k)+1]); }
#define L (p<<1)
#define R (L|1)
#define md ((l+r)>>1)
inl void PU(int p)
{
	TR &t=tr[p],l=tr[L],r=tr[R]; t.c=(l.v<=r.v)*l.c+(r.v<=l.v)*r.c; t.v=min(l.v,r.v)+t.t;
}
inl void BD(int p,int l,int r) {tr[p]={0,r-l+1}; l<r&&(BD(L,l,md),BD(R,md+1,r),0); }
inl void MD(int p,int l,int r,int la,int ra,int t)
{
	if(l>ra||r<la) return; if(l>=la&&r<=ra) return tr[p].v+=t, tr[p].t+=t, void();
	MD(L,l,md,la,ra,t); MD(R,md+1,r,la,ra,t); PU(p);
}
int main()
{
	n=Read(); m=Read(); for(int i=2;i<=n;++i) d[++dc]={i,i,1,i-1};
	for(int i=1;i<=n;++i) sa[0][i]=a[i]=Read();
	for(int i=1;i<=m;++i) ab=max(ab,b[i]=Read()), b[i]<ib&&(ib=b[id=i]);
	for(int i=1;i<=n;++i) a[i]+ab<0&&(d[++dc]={1,i,i,n},0);
	for(int l=1,r;l<=n;l=r+1) if(b[id]+a[l]>=0) r=l;
		else {for(r=l;r<=n&&b[id]+a[r+1]<0;++r); d[++dc]={l,r,l,r}; }
	for(int i=1;i<18;++i) for(int j=1;j<=n-(1<<i)+1;++j) sa[i][j]=max(sa[i-1][j],sa[i-1][j+(1<<(i-1))]);
	sb[0]=-V; for(int i=1,t=V,j=0;i<=m;++i) sb[i]=max(sb[i-1],b[i]), b[i]<V&&(j=i), bi[i]=j;
	for(int i=1;i<=n;++i)
	{
		int j=0,k=0,l,r; for(l=1,r=m;l<=r;) a[i]+sb[md]<0?(j=md,l=md+1):r=md-1;
		if(!j) continue; j=bi[j]; for(l=1,r=i;l<=r;) b[j]+Ask(md,i)<0?(k=md,r=md-1):l=md+1;
		d[++dc]={k,i,1,n};
	}
	sb[m+1]=-V; for(int i=m,t=V,j=0;i;--i) sb[i]=max(sb[i+1],b[i]), b[i]<V&&(j=i), bi[i]=j;
	for(int i=1;i<=n;++i)
	{
		int j=0,k=0,l,r; for(l=1,r=m;l<=r;) a[i]+sb[md]<0?(j=md,r=md-1):l=md+1;
		if(!j) continue; j=bi[j]; for(l=i,r=n;l<=r;) b[j]+Ask(i,md)<0?(k=md,l=md+1):r=md-1;
		d[++dc]={1,n,i,k};
	}
	for(int i=1,l,r;i<=dc;++i)
		c[d[i].lx].push_back({l=d[i].ly,r=d[i].ry,1}), c[d[i].rx+1].push_back({l,r,-1});
	BD(1,1,n); for(int i=1;i<=n;an+=(!tr[1].v)*tr[1].c,++i) for(C u:c[i]) MD(1,1,n,u.l,u.r,u.v);
	printf("%lld\n",an); return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 16084kb

input:

3 3
-1 0 1
-1 0 1

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 0ms
memory: 22288kb

input:

3 3
-1 0 1
1 0 1

output:

5

result:

ok single line: '5'

Test #3:

score: 0
Accepted
time: 0ms
memory: 24276kb

input:

10 10
145195799 312862766 143966779 -11056226 -503624929 636383890 -182650312 -382759112 -290767690 377894950
-845235881 -418232930 -600566938 -957917357 -181139226 125255273 -175406945 740226783 -750456842 325848662

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 0ms
memory: 18088kb

input:

10 10
923415743 -503391272 885740174 329644337 -693052351 -53764994 731859967 -834732760 -57751504 151969590
553689579 313784278 -12090771 921222379 -378313551 819586787 -373658045 559813071 671861309 268258615

output:

13

result:

ok single line: '13'

Test #5:

score: 0
Accepted
time: 0ms
memory: 20084kb

input:

10 10
-123276196 264891802 609485405 -980113903 152483893 57563748 -454135131 618686452 545983457 236619926
648896419 838269531 -380077537 536463844 89691984 38425645 759165084 325716532 330825142 -472414030

output:

12

result:

ok single line: '12'

Test #6:

score: 0
Accepted
time: 0ms
memory: 20264kb

input:

10 10
982508669 144806400 -503165973 760719995 -249757698 -573349946 -974145393 -905114292 218260516 -582308724
-341366248 187422683 298181900 -305351333 -616330465 -358958909 499163196 -967112195 -892547772 -605274022

output:

1

result:

ok single line: '1'

Test #7:

score: 0
Accepted
time: 0ms
memory: 22288kb

input:

10 10
-46634296 998649898 637256009 858343376 -339756903 750734027 533317110 509238419 -386390857 573123021
281094131 -798662878 454769235 -725579556 448648301 -937460999 -94310392 -504422439 -566805692 -883657655

output:

2

result:

ok single line: '2'

Test #8:

score: 0
Accepted
time: 3ms
memory: 18188kb

input:

10 10
-448680004 -918586552 -352190179 959516158 674275159 -778874335 -736749389 -368418013 103878020 562512923
-493932809 -736960513 78543198 885372691 -119140562 627952281 733778437 115556860 -196686999 -530143800

output:

3

result:

ok single line: '3'

Test #9:

score: -100
Wrong Answer
time: 0ms
memory: 22180kb

input:

10 10
438736217 -79057408 749090846 -106479211 -864134653 49806870 -724192950 -354806728 -230893984 130090227
-313678558 -493317070 -704907097 -240066585 275905249 -440144088 -697190358 608351624 783121279 -54163556

output:

2

result:

wrong answer 1st lines differ - expected: '1', found: '2'