专栏文章

问题解决但题未解决 P10403

个人记录参与者 1已保存评论 0

文章操作

快速查看文章及其快照的属性,并进行相关操作。

当前评论
0 条
当前快照
1 份
快照标识符
@miqm3t65
此快照首次捕获于
2025/12/04 07:02
3 个月前
此快照最后确认于
2025/12/04 07:02
3 个月前
查看原文
想到问题了,这样并不能遍历完所有区间,只能走到(1<<i)以及其加1长度的区间
思路是st表预处理的时候判断该区间的gcd是不是2,直接取值。
然后该区间向右扩展一格判断gcd是不是3,取值。
st表预处理时应该会把所有区间长为(1<<i)的区间都遍历一遍,然后区间长加1,这样应该遍历到了所有区间。
只过了Subtask 0 20pts
[测评记录](Subtask 0) 代码:
CPP
#include<bits/stdc++.h>
using namespace std;
const int N=6e5+5;
int n,st[N][20],lg[N],ans;
int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin>>n;
	lg[1]=0;
	for(int i=1;i<=n;i++){
		if(i!=1) lg[i]=lg[i>>1]+1;
		cin>>st[i][0];
		if(st[i][0]==3) ans++;
	}
//	cout<<ans<<endl;
	for(int j=1;j<=lg[n];j++)
		for(int i=1;i+(1<<j)-1<=n;i++){
			st[i][j]=__gcd(st[i][j-1],st[i+(1<<(j-1))][j-1]);
			if(st[i][j]==2){
//				printf("2(%d,%d) %d\n",i,i+(1<<j)-1,1<<j);
				ans+=(1<<j);
			} 
			if(i+(1<<j)<=n&&__gcd(st[i][j],st[i+(1<<j)][0])==3){
//				printf("3(%d,%d) %d\n",i,i+(1<<j),1+1<<j);
				ans+=1+(1<<j);
			}
		}	
	cout<<ans<<endl;
	return 0;
} 
/*
5
2 3 6 3 9
*/

评论

0 条评论,欢迎与作者交流。

正在加载评论...