8.18 NOIP analog test 25 (B) of the string + + Crow drinking camel door king Treasure

T1 string

Cattleya number

1 is set to (1, 1) go to 0 (1, -1) away, is the limit can not exceed $ y = 0 $ this line, into the meaning of problems starting from (0,0), go ( n + m, nm) does not cross the $ y = 0 $, then the number of bare Cattleya, $ ans = C (n + m, n) -C (n + m, m-1) $

 

#include<iostream>
#include<cstdio>
#include<cstring>
#define mod 20100403
#define ll long long
using namespace std;
ll n,m,inv[2001000],fac[2001000],facinv[2001000];
ll read()
{
    ll aa=0,bb=1;char cc=getchar();
    while(cc>'9'||cc<'0'){if(cc=='-') bb=-1;cc=getchar();}
    while(cc<='9'&&cc>='0'){aa=(aa<<3)+(aa<<1)+(cc^'0');cc=getchar();}
    return aa*bb;
}
ll C(ll x,ll y)
{
    return fac[x]*facinv[x-y]%mod*facinv[y]%mod;
}
int main()
{
    n=read();m=read();
    fac[0]=1;facinv[0]=1;inv[1]=1;
    for(ll i=1;i<=n+m;i++){
        if(i!=1) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
        fac[i]=fac[i-1]*i%mod;
        facinv[i]=facinv[i-1]%mod*inv[i]%mod;
    }
    printf("%lld\n",(C(n+m,n)-C(n+m,m-1)+mod)%mod);
    return 0;
}
String

 

 

T2 crow drink

Two properties:

1. Flow less drinking $ x $ times, then water more than he drank at least a $ x $ times. Therefore, in ascending order according to the number of drink.

2. The sorting sequence, the number of the current tank can drink the $ {\ ge} k $, then after the tank in this round will not be finished.

So we drained in sequence in sequence, each time to find the least, to see him drink a few rounds, jump directly, so with the right Fenwick tree maintenance the actual coordinates of the current point can also drink $ k $ times, if $ num > k + ans $ would fly round, while updating the answer, if $ num <k + ans $, to see him jump up to half of which (remember to update the answer) in the original sequence, while the index of the sorted sequence push the right one, because this one has expired.

Specific Fenwick tree is the realization of the original coordinates for the next standard, each insertion point is present, there are 1, 0 does not exist, the prefix and maintenance, query time can be obtained directly reduce the number of points on the right.

#include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
struct node
{
    int id,cnt;
}h[100100];
ll n,m,x,w[100100],a[100100],c[100100],ans,cir;
ll read()
{
    ll aa=0,bb=1;char cc=getchar();
    while(cc>'9'||cc<'0'){if(cc=='-') bb=-1;cc=getchar();}
    while(cc<='9'&&cc>='0'){aa=(aa<<3)+(aa<<1)+(cc^'0');cc=getchar();}
    return aa*bb;
}
bool cmp(node a,node b)
{
    return a.cnt==b.cnt?a.id<b.id:a.cnt<b.cnt;
}
int lowbit(int x)
{
    return x&(-x);
}
void insert(int x,int w)
{
    while(x<=n){
        c[x]+=w;
        x+=lowbit(x);
    }
}
int query(int x)
{
    int as=0;
    while(x){
        as+=c[x];
        x-=lowbit(x);
    }
    return as;
}
int main()
{
    n=read();m=read();x=read();
    for(int i=1;i<=n;i++) w[i]=read();
    for(int i=1,u;i<=n;i++){
        u=read();
        h[i].id=i;
        h[i].cnt=(x-w[i])/u+1;
        insert(i,1);
    }
    sort(h+1,h+n+1,cmp);
    int pos=1,las=1;//pos排序后的序列 las原序列
    for(int pos=1;pos<=n;pos++){
        while(cir<m&&query(n)-query(las-1)+ans<h[pos].cnt){
            cir++;
            ans+=query(n)-query(las-1);
            las=1;
        }
        if(cir>=m) break;
        int l=las,r=n,as=las-1;
        while(l<=r){
            int mid=(l+r)>>1;
            if(query(mid)-query(las-1)+ans<=h[pos].cnt){
                as=mid;
                l=mid+1;
            }
            else r=mid-1;
        }
        ans+=query(as)-query(las-1);
        las=(as==n)?1:as+1;
        if(as==n) cir++;
        insert(h[pos].id,-1);
    }
    printf("%lld\n",ans);
    return 0;
}
a crow drinks water

 

 

The camel gate T3 king Treasure

Exam questions wrong, around 8 o'clock understood as an expanded 8 points down to about, trained, trained, trained,

There are treasures of the place each portal can go build one-way side, tarjan point reduction, re-build the side, topu find the longest chain. (Because it is a one-way side, DFS is ($ n ^ 2 $), the time could not bear, topu requires only ($ n ^ 2 $))

Most disgusting side was built, with $ $ Vector stored in each row of each column which has a treasure (for $ opt == 1 || opt == 2 $), recording for each point is mapped $ $ Map tuple position (for $ opt == 3 $), and then built directly on the line

#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<queue>
using namespace std;
struct node
{
    int to,nxt;
}h[10000010],hh[1000100];
struct nnde
{
    int x,y,opt;
}t[100100];
int ans;
int n,r,c,tot,nxt[10000010],opt[100100],tx[9]={0,0,-1,-1 , - 1 , 1 , 1 , 1 }, ty [ 9 ] = {- 1 , 1 , - 1 , 0 , 1 , - 1 , 0 , 1 };
W nx [ 100100 ], Tet, d [ 100100 ] val [ 100100 ];
W dfn [ 100100 ], low [ 100100 ], S [ 100100 ], top, whos [ 100100 ], cnt, NUM, Shu [ 100100 ];
screw  is [ 100100],vis[100100],v[500100];
vector<int>hang[1001000],lie[1001000],ve;
map< pair<int,int> ,int>mp;
int read()
{
    int aa=0,bb=1;char cc=getchar();
    while(cc>'9'||cc<'0'){if(cc=='-') bb=-1;cc=getchar();}
    while(cc<='9'&&cc>='0'){aa=(aa<<3)+(aa<<1)+(cc^'0');cc=getchar();}
    return aa*bb;
}
void add(int x,int y)
{
    h[++tot].to=y;
    h[tot].nxt=nxt[x];
    nxt[x]=tot;
}
void ad(int x,int y)
{
    hh[++tet].to=y;
    hh[tet].nxt=nx[x];
    nx[x]=tet;
}
void tarjan(int x)
{
    dfn[x]=low[x]=++cnt;
    s[++top]=x;is[x]=1;
    for(int i=nxt[x];i;i=h[i].nxt){
        int y=h[i].to;
        if(!dfn[y]){
            tarjan(y);
            low[x]=min(low[x],low[y]);
        }
        else if(is[y]) low[x]=min(low[x],dfn[y]);
    }
    if(dfn[x]==low[x]){
        num++;
        while(1){
            int tmp=s[top--];
            whos[tmp]=num;
            shu[num]++;
            is[tmp]=0;
            if(tmp==x) break;
        }
    }
}
void topu()
{
    queue<int>q;
    for(int i=1;i<=num;i++){
        if(!d[i]) q.push(i),val[i]=shu[i],ans=max(ans,val[i]);
    }
    while(q.size()){
        int x=q.front();q.pop();
        for(int i=nx[x];i;i=hh[i].nxt){
            int y=hh[i].to;
            d[y]--;
            val[y]=max(val[y],val[x]+shu[y]);
            ans=max(ans,val[y]);
            if(!d[y]) q.push(y);
        }
    }
}
int main()
{
    n=read();r=read();c=read();
    int x,y,opt;
    for(int i=1;i<=n;i++){
        t[i].x=read();t[i].y=read();t[i].opt=read();
        hang[t[i].x].push_back(i);
        lie[t[i].y].push_back(i);
        mp[make_pair(t[i].x,t[i].y)]=i;
    }
    for(int i=1;i<=n;i++){
        int x=t[i].x,y=t[i].y,opt=t[i].opt;
        if(opt==1){
            for(int j=0;j<hang[x].size();j++){
                if(i==hang[x][j]) continue;
                add(i,hang[x][j]);
            }
        }
        else if(opt==2){
            for(int j=0;j<lie[y].size();j++){
                if(i==lie[y][j]) continue;
                add(i,lie[y][j]);
            }
        }
        else if(opt==3){
            for(int j=0;j<8;j++){
                if(mp[make_pair(x+tx[j],y+ty[j])]){
                    add(i,mp[make_pair(x+tx[j],y+ty[j])]);
                }
            }
        }
    }
    for(int i=1;i<=n;i++) if(!dfn[i]) tarjan(i);
    for(int i=1;i<=n;i++){
        ve.clear();
        for(int j=nxt[i];j;j=h[j].nxt){
            int y=h[j].to;
            if(whos[y]!=whos[i]&&!vis[whos[y]]){
                ad(whos[i],whos[y]);
                d[whos[y]]++;
                ve.push_back(whos[y]);
                vis[whos[y]]=1;
            }
        }
        for(int j=0;j<ve.size();j++) vis[ve[j]]=0;
    }
    topu();
    printf("%d\n",ans);
    return 0;
}
The camel door King's Treasure

 

Guess you like

Origin www.cnblogs.com/jrf123/p/11373828.html