QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#357902#3300. Cactus CompetitionwdnmdwrnmmpWA 1ms3868kbC++141.8kb2024-03-19 14:46:462024-03-19 14:46:47

Judging History

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

  • [2024-03-19 14:46:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3868kb
  • [2024-03-19 14:46:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<int> vi;
typedef pair<int,int> pi;

const int N=2e5+5,inf=1e9+5;
int n,m,a[N],b[N];
int pmn[N],pmx[N],smn[N],smx[N];
int mx0[N],mx1[N];
int le[N],ri[N];
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	cin>>n>>m;
	rep(i,1,n){
		cin>>a[i];
	}
	rep(i,1,m){
		cin>>b[i];
	}
	rep(i,1,m){
		pmn[i]=pmx[i]=b[i];
		if(i>=2){
			pmn[i]=min(pmn[i],pmn[i-1]);
			pmx[i]=max(pmx[i],pmx[i-1]);
		}
	}
	per(i,m,1){
		smn[i]=smx[i]=b[i];
		if(i<=m-1){
			smn[i]=min(smn[i],smn[i+1]);
			smx[i]=max(smx[i],smx[i+1]);
		}
	}
	rep(i,1,n){
		int p=upper_bound(pmn+1,pmn+m+1,-a[i],greater<int>())-pmn;
		mx0[i]=(p==1? -inf: pmx[p-1]);
		int q=lower_bound(smn+1,smn+m+1,-a[i])-smn;
		mx1[i]=(q>m? -inf: smx[q]);
	}
	vi stk;
	rep(i,1,n){
		while(!stk.empty() && a[stk.back()]<=a[i]){
			stk.pop_back();
		}
		le[i]=(stk.empty()?0:stk.back());
		stk.pb(i);
	}
	stk.clear();
	per(i,n,1){
		while(!stk.empty() && a[stk.back()]<a[i]){
			stk.pop_back();
		}
		ri[i]=(stk.empty()?n+1:stk.back());
		stk.pb(i);
	}
	int mn=pmn[n];
	long long ans=0;
	rep(i,1,n){
		if(a[i]+mn<0){
			continue;
		}
		int mnl=a[i],mnr=a[i];
		int cntl=0,cntr=0;
		per(j,i,le[i]+1){
			mnl=min(mnl,a[j]);
			int mx=mx0[j];
			if(mx+mnl>=0){
				cntl++;
				mnl=a[j];
			}
		}
		rep(j,i,ri[i]-1){
			mnr=min(mnr,a[j]);
			int mx=mx1[j];
			if(mx+mnr>=0){
				cntr++;
				mnr=a[j];
			}
		}
		// cout<<"?"<<i<<' '<<le[i]<<' '<<ri[i]<<'\n';
		ans+=(long long)cntl*cntr;
	}
	cout<<ans<<'\n';
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3576kb

input:

3 3
-1 0 1
-1 0 1

output:

1

result:

ok single line: '1'

Test #2:

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

input:

3 3
-1 0 1
1 0 1

output:

5

result:

ok single line: '5'

Test #3:

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

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

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

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

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

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: 0ms
memory: 3524kb

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: 0
Accepted
time: 1ms
memory: 3568kb

input:

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

output:

1

result:

ok single line: '1'

Test #10:

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

input:

10 10
910467973 475480237 284540173 -490003419 -496858639 575308046 -772115835 -650286781 -946294433 -375903216
465208966 198897340 37926241 -452764487 81169636 803610511 943188813 773420180 248487883 -932609634

output:

0

result:

ok single line: '0'

Test #11:

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

input:

10 10
-717662422 899539843 686516865 -308859590 731187727 948271874 -278705921 533338789 378708586 -53953529
-819295682 -712753496 -588162402 -765119207 518537239 793210677 199564253 443460314 248599384 333581283

output:

14

result:

ok single line: '14'

Test #12:

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

input:

10 10
13154473 419018121 -416088051 751464183 -782740304 257733919 -917880927 -690282918 410240353 817939924
440852087 -846511822 -519300757 153508300 757901474 928246448 -132837037 -603019187 860960474 -381787006

output:

0

result:

ok single line: '0'

Test #13:

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

input:

10 10
-357608489 679822152 25019791 265926477 -309098231 -7866110 -344995594 54868813 319830921 627547981
-431127028 -396320203 -35574917 657270168 -452580497 -359511978 -443174072 195670048 -696354158 2633147

output:

0

result:

ok single line: '0'

Test #14:

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

input:

10 10
126298083 -169291689 736314121 784469908 642788743 -450191333 -98804016 -511077469 -691147937 -275067405
440527703 -329746015 -473928781 -114255013 -450714278 -903623369 888225605 -146644734 173060316 214649350

output:

0

result:

ok single line: '0'

Test #15:

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

input:

10 10
-631748556 73286407 324751086 157696597 846447361 -444570059 484021795 -258058046 -116283058 -158063251
712663587 -233692952 820220037 516771553 879333593 156354440 -36643636 -639052753 -790959020 950256682

output:

30

result:

ok single line: '30'

Test #16:

score: -100
Wrong Answer
time: 1ms
memory: 3660kb

input:

20 10
-623445264 -424346675 38726811 -683309080 312098721 491569101 58067873 265188450 933087599 -786006093 -652539909 -790632832 780472328 -854541037 -851647529 130095820 35107516 -49396621 -476857996 -420750398
102904427 387758770 -297785914 -909492241 54351476 480814965 -450898650 532245762 14578...

output:

8

result:

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