QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#116335#3300. Cactus CompetitionWhaleAtColaWA 5ms23580kbC++141.8kb2023-06-28 15:36:422023-06-28 15:36:43

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-28 15:36:43]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:23580kb
  • [2023-06-28 15:36:42]
  • 提交

answer

#include<bits/stdc++.h>
#define re register
#define debug(...) fprintf(stderr,__VA_ARGS__);
using namespace std;
typedef long long ll;
typedef double db;
inline ll win(){
	ll x=0;bool w=0;char c=getchar();
	while(c<'0'||c>'9') w|=c=='-',c=getchar();
	while(c<='9'&&c>='0') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return w?-x:x;
}

const int N=202020;
const int inf=0x3f3f3f3f;
int st[21][N],ps[N],vl[N];

inline int bnd(int i,int lm){
	for(re int k=20;k>=0;--k)
		if(st[k][i]>=lm) i+=(1<<k);
	return i;
}

inline void sol(int n,int m,int *a,int *b,bool *t){
	int l=0;
	for(re int i=1,mx=-inf;i<=n;++i) if(mx<a[i]) mx=a[i],ps[++l]=i,vl[l]=a[i];
	memset(st,0xbf,sizeof st);
	for(re int i=1;i<=m;++i) st[0][i]=b[i];
	for(re int k=0;k<20;++k)
		for(re int i=1,j=(1<<k)+1,lj=m-(1<<k)+1;j<=lj;++i,++j)
			st[k+1][i]=min(st[k][i],st[k][j]);
	for(re int i=m,la=m+1,j,k;i>=1;--i){
		//first >b[i]
		if(b[i]>=vl[l]) t[i]=1,la=i;
		else{
			j=ps[upper_bound(vl+1,vl+l+1,b[i])-vl]-1;
//			debug("%d:%d\n",i,j);
			if(j){
				k=bnd(i,a[j])-1;//first <a[j]
				if(la<=k) t[i]=1,la=i;
			}
		}
	}
}

int a[N],b[N];bool tx[N],ty[N];
inline void rmain(){
	int m=win(),n=win(),mna=inf,mxa=-inf;ll ans=0;
	for(re int i=1;i<=m;++i) b[i]=win();
	for(re int i=1;i<=n;++i) a[i]=-win(),mna=min(mna,a[i]),mxa=max(mxa,a[i]);
	sol(n,m,a,b,tx);
	reverse(a+1,a+n+1),reverse(b+1,b+m+1);
	sol(n,m,a,b,ty);
	reverse(a+1,a+n+1),reverse(b+1,b+m+1);
	reverse(ty+1,ty+m+1);
//	for(re int i=1;i<=m;++i) debug("%d:%d %d\n",i,tx[i],ty[i]);
	for(re int i=m,yn=0,yc=0;i>=1;--i){
		if(b[i]<mna) yn=yc=0;
		if(ty[i]) ++yn;
		if(b[i]>=mxa) yc+=yn,yn=0;
		if(tx[i]) ans+=yc;
	}
	printf("%lld\n",ans);
}

signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
//	int T=win();while(T--)
	rmain();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 22196kb

input:

3 3
-1 0 1
-1 0 1

output:

1

result:

ok single line: '1'

Test #2:

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

input:

3 3
-1 0 1
1 0 1

output:

5

result:

ok single line: '5'

Test #3:

score: 0
Accepted
time: 1ms
memory: 22444kb

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: 1ms
memory: 22384kb

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: 5ms
memory: 22344kb

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: 1ms
memory: 23352kb

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: 2ms
memory: 22208kb

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: -100
Wrong Answer
time: 1ms
memory: 23304kb

input:

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

output:

2

result:

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