QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#116349#3300. Cactus CompetitionwfycswWA 2ms11688kbC++142.2kb2023-06-28 15:50:162023-06-28 15:50:20

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:50:20]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11688kb
  • [2023-06-28 15:50:16]
  • 提交

answer

#include<bits/stdc++.h>
#define RI register int
#define err puts("asd")	
#define ll long long
#define ull unsigned long long 
#define mk make_pair
#define LL __int128
#define fl fflush(stdout)
#define eb emplace_back
//#pragma GCC optimize(2)
//#define int long long 
using namespace std;

inline ll read(){
	ll s=0;register char c=getchar();bool f=0;
	while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}	
	while(c>='0'&&c<='9') s=(s<<1)+(s<<3)+c-48,c=getchar();
	return f?-s:s;
}

const int N=2e5+5;
const int inf=1e9+5;

int a[N],b[N],n,d[N],m,cnt,tong[N];
int maxl[N],minl[N],h[N],L[N],R[N],c[N],suf1[N],suf2[N],g[N];
ll ans;
bool vis[N];

struct ST{
	int f[20][N];
	
	inline void	init(){
		for(RI i=1;i<=n;++i);	
	}
};

signed main(){ 
//	dfreopen("1.cpp","r",stdin);
//	freopen("1.out","w",stdout);
	n=read();m=read();
	RI l,r,mid,pos,x,y,z,u,v,D=-1e9,F=1e9;
	for(RI i=1;i<=m;++i) b[i]=read();
	for(RI i=1;i<=n;++i) a[i]=read(),a[i]=-a[i],D=max(D,a[i]),F=min(F,a[i]);
	minl[0]=inf;
	maxl[1]=minl[1]=a[1];
	for(RI i=2;i<=n;++i) maxl[i]=max(maxl[i-1],a[i]),minl[i]=min(minl[i-1],a[i]);
	suf1[1]=suf2[1]=a[1];
	suf2[n+1]=inf;
	for(RI i=n-1;i>0;--i) suf1[i]=max(suf1[i+1],a[i]),suf2[i]=min(suf2[i+1],a[i]); 
	for(RI i=1;i<=m;++i){
		if(b[i]>=D) d[++cnt]=i,vis[i]=1,c[cnt]=1;
		else{
			h[i]=upper_bound(maxl+1,maxl+n+1,b[i])-maxl-1;
			l=1;r=n;pos=n+1;
			while(l<=r){
				mid=l+r>>1;
				if(suf1[mid]<=b[i]) r=mid-1,pos=mid;	
				else l=mid+1;
			}
			g[i]=pos;
		}
	}
	x=0;
	for(RI i=d[1];i<=m;++i){
		if(vis[i]){
			++x;y=d[i];z=inf;
			continue;
		}
		z=min(z,b[i]);
		if(z>=suf2[g[i]]) ++c[x];
	}
//	bool ok;L[1]=1;
//	for(RI i=2;i<=cnt;++i){
//		L[i]=i;ok=1;
//		for(RI j=d[i-1]+1;j<d[i];++j)
//			if(b[j]<F){ok=0;break;} 
//		if(ok) L[i]=L[i-1];
//	}
	bool ok;
	R[cnt]=cnt;
	for(RI i=cnt-1;i>0;--i){
		R[i]=i;ok=1;
		for(RI j=d[i+1]-1;j>d[i];--j)
			if(b[j]<F){ok=0;break;}
		if(ok) R[i]=R[i+1],c[i]+=c[i+1];	
	}
	x=cnt+1;
	for(RI i=d[cnt];i>0;--i){
		if(vis[i]){
			--x;y=d[i];z=inf;
			//cout<<"debug "<<c[x]<<endl;
			ans+=c[x];
			continue;
		}
		z=min(z,b[i]);
		//cout<<i<<' '<<z<<' '<<h[i]<<endl;
		if(z>=minl[h[i]]){
			ans+=c[x];
		}
	}
	cout<<ans<<endl;
	return 0; 
}





 

详细

Test #1:

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

input:

3 3
-1 0 1
-1 0 1

output:

1

result:

ok single line: '1'

Test #2:

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

input:

3 3
-1 0 1
1 0 1

output:

5

result:

ok single line: '5'

Test #3:

score: 0
Accepted
time: 2ms
memory: 11520kb

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: 11532kb

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

input:

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

output:

17

result:

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