社区讨论

为什么用快读快写全WA

P3865【模板】ST 表 & RMQ 问题参与者 3已保存回复 6

讨论操作

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

当前回复
6 条
当前快照
1 份
快照标识符
@lo7ir9il
此快照首次捕获于
2023/10/27 02:29
2 年前
此快照最后确认于
2023/10/27 02:29
2 年前
查看原帖
这段代码用快读快写在编译软件上正常出数,到洛谷上提交就都WA了,换成其他的输入输出就能过是为啥
CPP
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10,maxlog=18;
int a[maxn],st[maxn][maxlog],log_2[maxn];
inline ll read(){
	ll ret=0,w=1;
	char c=getchar();
	while(!isdigit(c)) {if(c=='-') w=-1;c=getchar();};
	while(isdigit(c)) {ret=(ret<<1)+(ret<<3)+(c^48);
	return ret*w;}
}
inline void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+48);
}
void init(){
	log_2[1]=0;log_2[2]=1;
	for(int i=3;i<maxn;i++) log_2[i]=log_2[i>>1]+1;
}
int main(){
	init();
    int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) cin>>st[i][0];
	for(int j=1;j<=maxlog;j++){
		for(int i=1;i+(1<<(j-1))-1<=n;i++){
			st[i][j]=max(st[i][j-1],st[i+(1<<(j-1))][j-1]);
		}
	}
	while(m--){
        int l,r;
		scanf("%d%d",&l,&r);
		int x=log_2[r-l+1];
		cout<<max(st[l][x],st[r-(1<<x)+1][x]);
		putchar('\n');
	}
	return 0;
}

回复

6 条回复,欢迎继续交流。

正在加载回复...