56RE,求助
查看原帖
56RE,求助
55227
魂逝_秦月歌楼主2020/8/3 23:25
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <cctype>
#include <queue>
#include <deque>
#include <ctime>
#include <cstring>
#include <string>
#define _e putchar (' ')
#define _v putchar ('\n')
#define ll long long
#define INF 999999999999999999ll
#define INE -999999999999999999ll
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
using namespace std;
inline int lowbit (int x) {
	return x&(-x);
}
inline int mx(int x,int y) {
	return x>y?x:y;
}
inline int mn(int x,int y) {
	return x<y?x:y;
}
inline void r(int &x) {
	int s=0,w=1;
	char ch=getchar ();
	while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar ();}
	while(ch>='0'&&ch<='9') {s=(s<<1)+(s<<3)+(ch^48); ch=getchar ();}
	x=s*w;
}
inline void wr(int x) {
	if(x<0) x=-x,putchar (45);
	if(x<10) {
		putchar (x+48);
		return ;
	}
	wr(x/10);
	putchar (x%10+48);
}
inline int ab (int x) {
	if(x<0) return -x;
	return x;
}
inline void swap (int &x,int &y) {
	x^=y^=x^=y;
}
const int N=200005;

int n,m,a[N],f[N][105];
struct node {
	int l,r;
}q[N];
int main () {
	memset(f,-1,sizeof(f));
	r(n),r(m);
	for(int i=1;i<=n;i++)
	    r(a[i]);
	for(int i=1;i<=m;i++)
	    r(q[i].l),r(q[i].r);
	for(int i=1;i<=n;i++)
	    f[i][0]=a[i];
	for(int j=1;(1<<j)<=n;j++) 
		for(int i=1;i+(1<<j-1)<=n;i++) 
			f[i][j]=max(f[i][j-1],f[i+(1<<j-1)][j-1]);
	for(int i=1;i<=m;i++) {
		int now=log2(q[i].r-q[i].l+1.0);
		wr(max(f[q[i].l][now],f[q[i].r-(1<<now)+1][now])),_v;
	}
	return 0;
}



56RE哪错了。。。我吐了我透

2020/8/3 23:25
加载中...