HYSBZ - 1067 ST算法

虽然不喜欢这种代码风格。。但是没有办法, ,自己写的已经超过承受时间了。。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define maxn 50005
using namespace std;
typedef long long ll;

int year[maxn], fall[maxn], d[maxn][20];
int n;
int solve(int l, int r){
	if(r < l)
	 return -1;
	int k = 0;
	while(1<<(k+1) <= r - l + 1)
	 k++;
	return max(d[l][k], d[r-(1<<k)+1][k]);
}
void ST(){

	for(int i = 0; i <= n; i++)
	 d[i][0] = fall[i];
	for(int j = 1; (1<<j) <= n; j++)
	  for(int i = 0; i + (1<<j) <= n; i++){
	  	 d[i][j] = max(d[i][j-1], d[i+(1<<(j-1))][j-1]);
	  }
}
int main(){

//	freopen("in.txt", "r", stdin);
	while(scanf("%d", &n) == 1){

		for(int i = 0; i < n; i++){
			scanf("%d%d", year+i, fall+i);
		}
		ST();
		int m, a, b;
		scanf("%d", &m);
		while(m--){
			scanf("%d%d", &a, &b);
			int l = lower_bound(year, year+n, a) - year, r = lower_bound(year, year+n, b) - year;
		    int s1 = 0, s2 = 0;
		    if(l == n || year[l] != a)
		      s1 = 1;
		    if(r == n || year[r] != b)
		      s2 = 1;
		    if(s1&&s2){
		    	puts("maybe");
		    	continue;
		    }
		    if(s1){
		    	int h = solve(l, r-1);
		    	if(h < fall[r])
		    	 puts("maybe");
		    	else
		    	 puts("false");
		    	continue;
		    }
		    if(s2){
		    	int h = solve(l+1, r-1);
		    	if(h < fall[l])
		    	 puts("maybe");
		    	else
		    	 puts("false");
		    	continue;
		    }
		    if(fall[r] > fall[l]){
		    	puts("false");
		    	continue;
		    }
		    int h = solve(l+1, r-1);
		    if(h < fall[r]){
		    	if(b-a+1 == r-l+1)
				 puts("true");
				else
				 puts("maybe");
		    }
		    else
		     puts("false");
		}
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值