AGC015 do title record

C

Properties of the tree is a point - edges = 1

Forest Unicom block count can do so directly maintain the prefix and then look like a border deal

//Love and Freedom.
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdio>
#define inf 20021225
#define ll long long
#define N 2100
using namespace std;
int read()
{
    int f=1,s=0; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9')    s=s*10+ch-'0',ch=getchar();
    return f*s;
}
int a[N][N],p[N][N],e[N][N],hp[N][N],lp[N][N],n,m; char ch[N];
int main()
{
    n=read(),m=read(); int Q=read();
    for(int i=1;i<=n;i++)
    {
        scanf("%s",ch+1);
        for(int j=1;j<=m;j++)
        {
            a[i][j]=ch[j]-'0';
            p[i][j]=p[i-1][j]+p[i][j-1]-p[i-1][j-1]+a[i][j];
            e[i][j]=e[i-1][j]+e[i][j-1]-e[i-1][j-1]+(a[i][j]&a[i-1][j])+(a[i][j-1]&a[i][j]);
            hp[i][j]=hp[i][j-1]+(a[i][j]&a[i-1][j]);
            lp[i][j]=lp[i-1][j]+(a[i][j]&a[i][j-1]);
        }
    }
    while(Q--)
    {
        int h1=read(),l1=read(),h2=read(),l2=read();
        int poi=p[h2][l2]-p[h2][l1-1]-p[h1-1][l2]+p[h1-1][l1-1];
        //printf("%d %d %d %d\n",p[h2][l2],p[h2][l1-1],p[h1-1][l2],p[h1-1][l1-1]);
        int ed=e[h2][l2]-e[h2][l1-1]-e[h1-1][l2]+e[h1-1][l1-1];
        //printf("%d ",ed);
        ed -= hp[h1][l2]-hp[h1][l1-1];
        ed -= lp[h2][l1]-lp[h1-1][l1];
        //printf("%d %d %d %d\n",hp[h1][l2],hp[h1][l1-1],lp[h2][l1],lp[h1-1][l1]);
        printf("%d\n",poi-ed);
    }
    return 0;
}
C

 

D

God idea title (I did not mind)

Consider first AB of the longest common prefix will be able to lose

1A and then the next one is 0 and B is

What set this one I was p

Consider [A, 1 << p) answers and [1 << p, B] answers

Obviously just take the answer is in front of a set (1 << p) -A

Just take us back to consider the next highest position B denoted by a 1 k

The answer is [1 << p, (1 << p) + (1 << k + 1) -1]

The last two are considered to take the answer is [(1 << p) + A, (2 << p) -1]

We found later need to take two and

The main idea is that the value of such practice is therefore the answer is the interval range

//Love and Freedom.
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdio>
#define inf 20021225
#define ll long long
using namespace std;
int read()
{
    int f=1,s=0; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9')    s=s*10+ch-'0',ch=getchar();
    return f*s;
}
int main()
{
    ll a,b; scanf("%lld%lld",&a,&b); ll ans=0;
    if(a==b)    return puts("1"),0;
    for(int i=60;~i;i--)
        if((a>>i&1)!=(b>>i&1))
        {
            a&=(1ll<<i+1)-1; b&=(1ll<<i)-1;
            ll p=1ll<<i; ans+=p-a;
            for(;~i;i--)    if(b>>i&1)    break;
            i++; ans+=1ll<<i; a=max(1ll<<i,a);
            //printf("%lld %lld %lld\n",ans,i,a);
            ans+=p-a;
            break;
        }
    printf("%lld\n",years);
    return  0 ; 
}
D

 

E

In fact, a step backward (withered

Consider a point can be dyed point

There are apparently two

1.xj<xi vj>vj

2.xj> vi xi VJ <

We continue to consider a number of complex

Found in the current position for maximum points if larger than its speed, then it will certainly all speeds less than the speed of the previous point of this all points staining maximum (think about why?)

Similarly behind

Therefore, according to the speed after sorted into a number of sections covered by the program

Obviously segment tree can be optimized (Oh, in fact, can be directly prefixes and optimization Unfortunately, I lazy qwq)

So it is done

//Love and Freedom.
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdio>
#define inf 20021225
#define ll long long
#define N 200100
#define mdn 1000000007
#define ls (x<<1)
#define rs (x<<1|1)
#define mid (l+r>>1)
using namespace std;
int read()
{
    int f=1,s=0; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9')    s=s*10+ch-'0',ch=getchar();
    return f*s;
}
void upd(int &x,int y){x+=x+y>=mdn?y-mdn:y;}
int t[N<<2];
void pushup(int x){t[x]=(t[ls]+t[rs])%mdn;}
void modify(int x,int l,int r,int d,int val)
{
    if(l==r){upd(t[x],val); return;}
    if(d<=mid)    modify(ls,l,mid,d,val);
    else    modify(rs,mid+1,r,d,val);
    pushup(x);
}
int query(int x,int l,int r,int LL,int RR)
{
    if(LL<=l&&RR>=r)    return t[x]; int ans=0;
    if(LL<=mid)    upd(ans,query(ls,l,mid,LL,RR));
    if(RR>mid)    upd(ans,query(rs,mid+1,r,LL,RR));
    return ans;
}
struct node{int x,v,idx,idv;}a[N];
struct seg{int l,r;}s[N];
bool operator<(seg a,seg b){return a.r<b.r||(a.r==b.r&&a.l<b.l);}
bool cmpv(node x,node y){return x.v<y.v;}
bool cmpx(node x,node y){return x.x<y.x;}
int pre[N],suf[N],n,v[N];
int main()
{
    n=read();
    for(int i=1;i<=n;i++)    a[i].x=read(),a[i].v=read();
    sort(a+1,a+n+1,cmpv);
    for(int i=1;i<=n;i++)    a[i].idv=i,v[i]=a[i].v;
    sort(a+1,a+n+1,cmpx); //suf[n+1]=inf*99;
    for(int i=1;i<=n;i++)
    {
        if(i==1)    pre[1]=a[1].idv;
        else
        {
            if(a[i].v>v[pre[i-1]])    pre[i]=a[i].idv;
            else    pre[i]=pre[i-1];
        }
        a[i].idx=i;
    }
    for(int i=n;i;i--)
    {
        if(i==n)    suf[n]=a[n].idv;
        else
        {
            if(a[i].v<v[suf[i+1]])    suf[i]=a[i].idv;
            else    suf[i]=suf[i+1];
        }
    }
    modify(1,0,n,0,1);
    for(int i=1;i<=n;i++)
    {
        int r=pre[a[i].idx],l=suf[a[i].idx];
        s[i].l=l; s[i].r=r;
    }
    sort(s+1,s+n+1);
    for(int i=1;i<=n;i++)
    {
        int l=s[i].l,r=s[i].r;
        int val=query(1,0,n,l-1,r);
        modify(1,0,n,r,val);
    }
    printf("%d\n",query(1,0,n,n,n));
    return 0;
}
E

 

F

The first question is clearly Fib (yesterday just like Europe then learn fast response thief)

The second question also 8 will wait for me goo

Guess you like

Origin www.cnblogs.com/hanyuweining/p/11980182.html