UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#199929#3467. 好的序列xue_gui_jian_chi1001720ms55776kbC++2.6kb2023-12-24 10:55:032023-12-24 12:12:15

answer

/*int le(int x){return x<<1;}
int re(int x){return (x<<1)+1;}

struct nd{
	int l,r;
	int ls,rs;
	int mx;
	int mn;
}a[1000005];

void update(int x){
	a[x].mx = max(a[le].mx,a[re].mx);
	a[x].mn = min(a[le].mn,a[re].mn);
}

void build(int x,int l,int r){
	a[x].l = l;
	a[x].r = r;
	a[x].mx = -0x3f3f3f3f;
	a[x].mn = 0x3f3f3f3f;
	if(l == r){
		a[x].val = a[l];
		return;
	}
	int mid = (l+r)>>1;
	build(le(x),l,mid);
	build(re(x),mid+1,r);
	a[x].ls = le(x);
	a[x].rs = re(x);
	update(x);
}*/
#include<bits/stdc++.h>

#define st s[t]
#define s1 s[1]
#define s2 s[2]
#define s3 s[3]
#define s4 s[4]
#define ft f[t]
#define f1 f[1]
#define f2 f[2]
#define f3 f[3]
#define f4 f[4]
#define tpt tp[t]
#define tp1 tp[1]
#define tp2 tp[2]
#define tp3 tp[3]
#define tp4 tp[4]
#define int long long

using namespace std;

int n,ans;
int a[1000005];
int mp[1000005];

int s[5][1000005];
int f[5][1000005];
int tp[5];

int read(){
    int x = 0,y = 1;
    char ch = getchar();
    while(ch > '9'||ch < '0'){
        if(ch == '-') y = -1;
        ch = getchar();
    }
    while(ch <= '9'&&ch >= '0'){
        x = x*10+ch-'0';
        ch = getchar();
    }
    return x*y;
}

void pu1(int t,int x){
	while(tpt > 0&&a[st[tpt]] < a[x]){
		ft[st[tpt]] = x;
		tpt--;
	}
	st[++tpt] = x;
}

void pu2(int t,int x){
	while(tpt > 0&&a[st[tpt]] < a[x]){
		ft[st[tpt]] = x;
		tpt--;
	}
	st[++tpt] = x;
}

void pu3(int t,int x){
	while(tpt > 0&&a[st[tpt]] > a[x]){
		ft[st[tpt]] = x;
		tpt--;
	}
	st[++tpt] = x;
}

void pu4(int t,int x){
	while(tpt > 0&&a[st[tpt]] > a[x]){
		ft[st[tpt]] = x;
		tpt--;
	}
	st[++tpt] = x;
}

signed main(){
	
	n = read();
	for(int i = 1;i <= n;++ i)
		a[i] = read(),mp[a[i]] = i; 
	
	for(int i = 1;i <= n;++ i)
		pu2(2,i),pu4(4,i);
	for(int i = n;i >= 1;-- i)
		pu1(1,i),pu3(3,i);
	
	for(int i = 1;i <= n;++ i){
		for(int j = i;j <= n;j += i){
			if(mp[i] <= mp[j]){
				int xz = f3[mp[i]];
				int xy = f4[mp[i]];
				int dz = f1[mp[j]];
				int dy = f2[mp[j]];
				if(!xy) xy = n+1;
				if(!dy) dy = n+1; 
				if(xy < mp[j]||dz > mp[i]) continue;
				int l = max(xz,dz);
				int r = min(xy,dy);
				int ll = mp[i]-l;
				int rr = r-mp[j];
				ans += ll*rr;
			}
			else{
				int xz = f3[mp[i]];
				int xy = f4[mp[i]];
				int dz = f1[mp[j]];
				int dy = f2[mp[j]];
				if(!xy) xy = n+1;
				if(!dy) dy = n+1; 
				if(dy < mp[i]||xz > mp[j]) continue;
				int l = max(xz,dz);
				int r = min(xy,dy);
				int ll = mp[j]-l;
				int rr = r-mp[i];
				ans += ll*rr;
			}
		}
	}
	
	cout << ans;
	
	return 0;
	
} 

详细

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

Test #1:

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

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

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

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: 228ms
memory: 48048kb

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: 253ms
memory: 48052kb

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: 235ms
memory: 48048kb

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: 201ms
memory: 55776kb

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: 243ms
memory: 53312kb

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: 248ms
memory: 52820kb

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: 312ms
memory: 52944kb

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