UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#199896#3467. 好的序列LDM0116100962ms35288kbC++112.1kb2023-12-24 10:01:072023-12-24 12:04:14

answer

#include<bits/stdc++.h>
#define ll long long
#define mkp make_pair
#define gc() (p1==p2&&(p2=(p1=b)+fread(b,1,n,stdin),p1==p2)?EOF:*p1++)
#define inf 0x3f3f3f3f
using namespace std;
namespace r{
	const int n=10000000;
	char *p1,*p2,b[n];
	inline int read(){
		int x=0,f=1;
		char c=gc();
		while(!isdigit(c)){
			if(c==45) f=-1;
			c=gc();
		}
		while(isdigit(c)){
			x=(x<<1)+(x<<3)+c-'0';
			c=gc();
		}
		return x*f;
	}
	random_device r;
	mt19937 rd(r());
	inline int rand(int l,int r){
		return uniform_int_distribution<int>(l,r)(rd);
	}
}
using namespace r;
namespace w{
	const int s=1;
	char b[s];
	int cnt=0;
	inline void write(ll x){
		if(x<0){
			x=-x;
			b[cnt++]=45;
			if(cnt==s) fwrite(b,1,cnt,stdout),cnt=0;
		}
		if(x>9) write(x/10);
		b[cnt++]=(x%10)|48;
		if(cnt==s) fwrite(b,1,cnt,stdout),cnt=0;
	}
	inline void space(){
		b[cnt++]=' ';
		if(cnt==s) fwrite(b,1,cnt,stdout),cnt=0;
	}
	inline void endl(){
		b[cnt++]='\n';
		if(cnt==s) fwrite(b,1,cnt,stdout),cnt=0;
	}
	inline void show(){
		if(cnt) fwrite(b,1,cnt,stdout),cnt=0;
	}
}
using namespace w;
namespace ldm{
	int n,a[1000001],s[1000001],t,x[1000001],lmin[1000001],rmin[1000001],lmax[1000001],rmax[1000001];
	ll ans;
	int main(){
		n=read();
		for(int i=1;i<=n;i++){
			a[i]=read();
			x[a[i]]=i;
		}
		for(int i=1;i<=n;i++){
			while(t&&a[s[t]]>a[i]){
				t--;
			}
			lmin[a[i]]=s[t]+1;
			s[++t]=i;
		}
		t=0;
		s[0]=n+1;
		for(int i=n;i>=1;i--){
			while(t&&a[s[t]]>a[i]){
				t--;
			}
			rmin[a[i]]=s[t]-1;
			s[++t]=i;
		}
		t=0;
		s[0]=0;
		for(int i=1;i<=n;i++){
			while(t&&a[s[t]]<a[i]){
				t--;
			}
			lmax[a[i]]=s[t]+1;
			s[++t]=i;
		}
		t=0;
		s[0]=n+1;
		for(int i=n;i>=1;i--){
			while(t&&a[s[t]]<a[i]){
				t--;
			}
			rmax[a[i]]=s[t]-1;
			s[++t]=i;
		}
		for(ll i=1;i<=n;i++){
			for(ll j=1;j*i<=1ll*n;j++){
				ll l=max(lmin[i],lmax[j*i]),r=min(rmin[i],rmax[j*i]),ld=min(x[i],x[j*i]),rd=max(x[i],x[j*i]);
				ans+=max(0ll,(ld-l+1))*max(0ll,(r-rd+1));
			}
		}
		write(ans);
		return 0;
	}
}
int main(){
	ldm::main();
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1272kb

input:

1000
381 165 79 257 333 129 548 536 171 765 460 238 380 950 572 880 806 49 64 786 289 530 689 624 18...

output:

305063

result:

ok single line: '305063'

Test #2:

score: 10
Accepted
time: 0ms
memory: 1272kb

input:

1000
433 295 37 956 891 333 237 26 553 637 487 725 713 133 826 549 918 351 35 244 606 52 951 664 776...

output:

341996

result:

ok single line: '341996'

Test #3:

score: 10
Accepted
time: 0ms
memory: 1268kb

input:

1000
338 770 597 105 357 82 928 446 139 341 495 583 328 630 451 37 507 109 985 744 430 416 599 90 34...

output:

349237

result:

ok single line: '349237'

Test #4:

score: 10
Accepted
time: 132ms
memory: 35284kb

input:

999988
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ...

output:

13969781

result:

ok single line: '13969781'

Test #5:

score: 10
Accepted
time: 148ms
memory: 35288kb

input:

999996
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ...

output:

13969905

result:

ok single line: '13969905'

Test #6:

score: 10
Accepted
time: 128ms
memory: 35284kb

input:

999996
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ...

output:

13969905

result:

ok single line: '13969905'

Test #7:

score: 10
Accepted
time: 144ms
memory: 33944kb

input:

1000000
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 ...

output:

224723756902

result:

ok single line: '224723756902'

Test #8:

score: 10
Accepted
time: 133ms
memory: 33908kb

input:

1000000
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102...

output:

227698224579

result:

ok single line: '227698224579'

Test #9:

score: 10
Accepted
time: 144ms
memory: 33648kb

input:

1000000
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 10...

output:

243107468676

result:

ok single line: '243107468676'

Test #10:

score: 10
Accepted
time: 133ms
memory: 33712kb

input:

1000000
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 ...

output:

240362325686

result:

ok single line: '240362325686'

Extra Test:

score: 0
Extra Test Passed