萌新刚学OI,求助50pts/kk
查看原帖
萌新刚学OI,求助50pts/kk
298549
SIXIANG32楼主2020/9/29 18:09
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<map>
#include<cmath>
using namespace std;
int f[1010000][21],n,m,a[100010];
map<int,int>year;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
inline void write(int x)
{
    char f[200];
    int tmp=x>0?x:-x,cnt=0;
    if(x<0)putchar('-');
    while(tmp>0)f[cnt++]=tmp%10+'0',tmp/=10;
    while(cnt>0)putchar(f[--cnt]);
    putchar('\n');
}
void ST()
{
	for(int i=1;i<=20;i++)
		for(int p=1;p<=n-(1<<i)+1;p++)
			f[p][i]=max(f[p][i-1],f[p+(1<<(i-1))][i-1]);
}
int ask(int l,int r)
{
	int Log=log2(r-l+1);
	return max(f[l][Log],f[r-(1<<Log)+1][Log]);
}
int main()
{
	n=read();
	for(int p=1,x,y;p<=n;p++)
	{
		cin>>x>>y;
		year[x]=p,f[p][0]=y;
	}
	ST();
	m=read();
	for(int p=1,x,y;p<=m;p++)
	{
		cin>>y>>x;
		int flag=0;
		if(x<=y)
		{
			cout<<"false"<<endl;
			continue;
		}
		if((!year[y]&&year[x])||(!year[x]&&year[y]))
		{
			if(year[x]-year[y]>1)
			{
				while(!year[y])y++;
				if(y>=x)
				{
					cout<<"maybe"<<endl;
					continue;
				}
				if(ask(year[y],year[x]-1)>=f[year[x]][0])
				{
					cout<<"false"<<endl;
					continue;
				}
				else
					cout<<"maybe"<<endl;
				continue;
			}
			else cout<<"maybe"<<endl;
			continue;
		}
		if(x-y==1)
		{
			if(year[x]-year[y]!=1)
			{
				cout<<"maybe"<<endl;
				continue;
			} 
			if(f[year[y]][0]<f[year[x]][0])
				cout<<"false"<<endl;
			else
				cout<<"ture"<<endl;
			continue;
		}
		if(f[year[y]][0]<f[year[x]][0])
		{
			cout<<"false"<<endl;
			continue;
		}
		if(!year[y]&&!year[x])
		{
			cout<<"maybe"<<endl;
			continue;
		}
		if(year[x]-year[y]!=x-y)
		{
			if(year[x]-year[y]>1)
			{
				if(ask(year[y]+1,year[x]-1)>=f[year[x]][0])
				{
					cout<<"false"<<endl;
					continue;
				}
				else
					cout<<"maybe"<<endl;
				continue;
			}
			else cout<<"maybe"<<endl;
			continue;
		}
		if(ask(year[y]+1,year[x]-1)>=f[year[x]][0])
		{
			cout<<"false"<<endl;
			continue;
		}
		cout<<"ture"<<endl;
	}
}

数据太大,调不动了/kk

2020/9/29 18:09
加载中...