新人求助,降雨量...算了不btd了,50pts求助
查看原帖
新人求助,降雨量...算了不btd了,50pts求助
312393
ADay楼主2020/6/8 22:38

思路是用分块维护区间最大值,50pts

#include<bits/stdc++.h>
#define Maybe {puts("maybe");continue;}
#define True {puts("true");continue;}
#define False {puts("false");continue;}
#define max(x,y) (x>y?x:y)
#define rg register
using std::unordered_map;
using std::lower_bound;
using std::upper_bound;

#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;

inline int read()
{
    rg int s=0,f=1;
    rg char ch=getchar();
    while(!isdigit(ch))
    {
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        s=s*10+ch-48;
        ch=getchar();
    }
    return s*f;
}

int n,m,y[50005],r[50005],px,py,bl[50005],num,mx[50005];
unordered_map<int,int>p;

int getmax(int ll,int rr)
{
    rg int res=-1;
    if(!p[ll])
        ll=y[lower_bound(y+1,y+n+1,ll)-y];
    if(!p[rr])
        rr=y[upper_bound(y+1,y+n+1,rr)-y-1];
    for(rg int i=ll;i<=rr&&i<=y[bl[p[ll]]*num];i=y[p[i]+1])
        res=max(res,r[p[i]]);//,printf("%d ",i);
    //puts("");
    if(bl[p[ll]]!=bl[p[rr]])
        for(rg int i=y[(bl[p[rr]]-1)*num+1];i<=rr;i=y[p[i]+1])
        {
            res=max(res,r[p[i]]);//,printf("%d ",i);
            if(p[i]==n)break;
        }
    //puts("");
    for(rg int i=bl[p[ll]]+1;i<bl[p[rr]];i++)
        res=max(res,mx[i]);//,printf("%d",i);
    //puts("");
    //printf("max:%d\n",res);
    return res;
}

int main()
{
    n=read();num=sqrt(n);
    for(rg int i=1;i<=n;i++)
    {
        y[i]=read();
        r[i]=read();
        p[y[i]]=i;
        bl[i]=(i-1)/num+1;
        mx[bl[i]]=max(mx[bl[i]],r[i]);
    }
    m=read();
    while(m--)
    {
        px=read();py=read();
        if(px>=py)False
        rg int maxget=getmax(px+1,py-1);
        if(!p[py])
        {
            if(!p[px])Maybe
            if(r[p[px]]>maxget)Maybe
            False
        }
        if(p[px])
        {
            if(r[p[px]]<r[p[py]])False
            if(maxget>=r[p[py]])False
            if(py-px==p[py]-p[px])True
            Maybe
        }
        if(r[p[py]]<=maxget)False
        Maybe
    }
    return 0;
}

不急,离线等

2020/6/8 22:38
加载中...