zoukankan      html  css  js  c++  java
  • 2018.10.15noip模拟赛

    题目和题解看这里

    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    inline int read()
    {
        int x=0,f=1;char c=getchar();
        for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
        for(;isdigit(c);c=getchar()) x=x*10+c-'0';
        return f*x;
    }
    inline ll Lead()
    {
        ll x=0,f=1;char c=getchar();
        for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
        for(;isdigit(c);c=getchar()) x=x*10+c-'0';
        return f*x;
    }
    int T,l,f;
    char S[20];
    int A[20];
    int Hsh[20][1000010];
    void dfs(int x,ll val,ll now)
    {
        if(x==l||val>=1000000) return;
        Hsh[x][val]=1;
        dfs(x+1,val+A[x+1],A[x+1]);
        dfs(x+1,val+A[x+1]+now*9,now*10+A[x+1]);
    }
    ll calc(ll x)
    {
        if(x==0) return 10;
        ll t=1;
        while(x>0)x/=10,t*=10;
        return t;
    }
    void dfs2(int x,ll val,ll now)
    {
        if(x==1||val>=1000000) return;
        if(Hsh[x-1][val]==1) f=1;
        dfs2(x-1,val+A[x-1],A[x-1]);
        dfs2(x-1,val+A[x-1]*calc(now),now+A[x-1]*calc(now));
    }
    int main()
    {
        freopen("equation.in","r",stdin);
        freopen("equation.out","w",stdout);
        T=read();
        while(T--)
        {
            memset(Hsh,0,sizeof(Hsh));
            f=0;
            scanf("%s",S+1);
            l=strlen(S+1);
            for(int i=1;i<=l;i++) A[i]=S[i]-'0';
            dfs(1,A[1],A[1]);    
            dfs2(l,A[l],A[l]);
            if(f) {printf("Yes
    ");continue;}
            printf("No
    ");
        }
    }
    T1
    #include<bits/stdc++.h>
    #define ll long long
    #define int long long
    using namespace std;
    inline int read()
    {
        int x=0,f=1;char c=getchar();
        for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
        for(;isdigit(c);c=getchar()) x=x*10+c-'0';
        return f*x;
    }
    inline ll Lead()
    {
        ll x=0,f=1;char c=getchar();
        for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
        for(;isdigit(c);c=getchar()) x=x*10+c-'0';
        return f*x;
    }
    int n,m,q,P[160010];
    int fst[160010],nxt[320010],to[320010],cnt;
    int dfn[160010],dcnt,siz[160010],dep[160010];
    int st[160010][20],op[160010];
    void link(int x,int y)
    {
        nxt[++cnt]=fst[x];
        fst[x]=cnt;to[cnt]=y;
    }
    void dfs(int x)
    {
        dfn[x]=++dcnt;
        siz[x]=1;
        for(int i=fst[x];i;i=nxt[i])
        {
            if(dep[to[i]]!=0) continue;
            dep[to[i]]=dep[x]+1;
            st[to[i]][0]=x;
            dfs(to[i]);
            siz[x]+=siz[to[i]];
        }
    }
    void makest()
    {
        for(int i=1;i<=18;i++)
        {
            for(int j=1;j<=n;j++)
            {
                st[j][i]=st[st[j][i-1]][i-1];
            }
        }
    }
    int calc(int x,int stp)
    {
        if(dep[x]<=stp) return 1;
        for(int i=0;(1<<i)<=stp;i++)
        {
            if(stp&(1<<i)) x=st[x][i];
        }
        return x;
    }
    namespace Seg_Tree
    {
        #define lx (x<<1)
        #define rx ((x<<1)|1)
        int tag1[3020010],tag2[3020010];
        void psd(int x)
        {
            if(tag1[x])
            {
                tag1[lx]=tag1[x];
                tag1[rx]=tag1[x];
                tag2[lx]=tag2[rx]=0;
                tag1[x]=0;
            }
            if(tag2[x])
            {
                tag2[lx]+=tag2[x];
                tag2[rx]+=tag2[x];
                tag2[x]=0;
            }
        }
        void mdf1(int x,int l,int r,int nl,int nr,int val)
        {
            if(r<l) return;
            if(nl<=l&&r<=nr) 
            {
                tag1[x]=val;tag2[x]=0;return;
            }
            psd(x);
            int mid=(l+r)>>1;
            if(nl<=mid) mdf1(lx,l,mid,nl,nr,val);
            if(nr>mid) mdf1(rx,mid+1,r,nl,nr,val);
        }
        void mdf2(int x,int l,int r,int nl,int nr,int val)
        {
            if(r<l) return;
            if(nl<=l&&r<=nr) 
            {
                tag2[x]+=val;return;
            }
            psd(x);
            int mid=(l+r)>>1;
            if(nl<=mid) mdf2(lx,l,mid,nl,nr,val);
            if(nr>mid) mdf2(rx,mid+1,r,nl,nr,val);
        }
        int qury(int x,int l,int r,int p)
        {
            if(l==r) return calc(tag1[x]==0?P[l]:tag1[x],tag2[x]);
            psd(x);
            int mid=(l+r)>>1;
            if(p<=mid) return qury(lx,l,mid,p);
            if(p>mid) return qury(rx,mid+1,r,p);
        }
    }
    using namespace Seg_Tree;
    namespace Fenwick_Tree
    {
        #define lowbit(x) (x&-x)
        ll c1[160010],c2[160010];
        void add1(int p,ll val){for(int i=p;i<=n;i+=lowbit(i)) c1[i]+=val;}
        void add2(int p,ll val){for(int i=p;i<=n;i+=lowbit(i)) c2[i]+=val;}
        ll qury1(int p){ll tmp=0;for(int i=p;i>0;i-=lowbit(i)) tmp+=c1[i];return tmp;}
        ll qury2(int p){ll tmp=0;for(int i=p;i>0;i-=lowbit(i)) tmp+=c2[i];return tmp;}
    }
    using namespace Fenwick_Tree;
    signed main()
    {
        freopen("robot3.in","r",stdin);
        freopen("robot.out","w",stdout);
        n=read();m=read();
        for(int i=1;i<n;i++)
        {
            int x=read(),y=read();
            link(x,y);link(y,x);
        }
        dep[1]=1;
        dfs(1);makest();
        for(int i=1;i<=m;i++) P[i]=read();
        q=read();
        for(int i=1;i<=q;i++)
        {
            int opt=read();
            if(opt==3) 
            {
                int x=read();
                int now=qury(1,1,m,x);
                op[now]=!op[now];
                if(op[now]==1)add1(dfn[now],dep[now]),add2(dfn[now],1ll);
                else add1(dfn[now],-dep[now]),add2(dfn[now],-1ll);
                ll sum=qury1(dfn[now]+siz[now]-1)-qury1(dfn[now]);
                ll num=qury2(dfn[now]+siz[now]-1)-qury2(dfn[now]);
                printf("%lld
    ",sum-num*dep[now]);
                continue;
            }
            int l=read(),r=read(),val=read();
            if(opt==1) mdf1(1,1,m,l,r,val);
            if(opt==2) mdf2(1,1,m,l,r,val);
        }
    }
    T3
  • 相关阅读:
    「Wallace 笔记」K-D tree 区域查询时间复杂度简易证明
    「LOJ #2980」「THUSCH 2017」大魔法师
    「Wallace 笔记」快速上手回文自动机(PAM)
    「ZJU Summer Training 2020
    「AtCoder AGC002F」Leftmost Ball
    文案高手的18项修炼
    高性能MySQL实战
    300分钟搞懂 Spring Cloud
    腾讯产品启示录
    300分钟吃透分布式缓存
  • 原文地址:https://www.cnblogs.com/wjxgy/p/9794075.html
Copyright © 2011-2022 走看看