Test 40

#include<bits/stdc++.h>
#define F(i,a,b) for(rg int i=a;i<=b;++i)
#define LL long long
#define il inline
#define rg register
#define pf(a) printf("%d ",a)
#define phn puts("")
using namespace std;
int read();
#define N 200010
int n,lmt;
int a[N],b[N],c[N<<1];
il int max(int x,int y){return x>y?x:y;}
struct tree{
    int w,g,l,r;
}s[N<<2];
#define sx s[x]
void biu(int x,int l,int r){
    sx.l=l;sx.r=r;sx.w=sx.g=0;
    if(l==r)return ;
    int mid=l+r>>1;
    biu(x<<1,l,mid);biu(x<<1|1,mid+1,r);
}
#define lc s[x<<1] 
#define rc s[x<<1|1]
il void down(int x){
    lc.w+=sx.g;lc.g+=sx.g;
    rc.w+=sx.g;rc.g+=sx.g;
    sx.g=0;
}    
void upd(int x,int p,int val){
    if(sx.l==sx.r){
        sx.w=max(val,sx.w);
        return ;
    }
    if(sx.g)down(x);
    int mid=sx.l+sx.r>>1;
    if(p<=mid)upd(x<<1,p,val);
    else upd(x<<1|1,p,val);
    sx.w=max(lc.w,rc.w);
}
void add(int x,int l,int r){
    if(l<=sx.l&&sx.r<=r){
        sx.w++;sx.g++;
        return ;
    }
    if(sx.g)down(x);
    int mid=sx.l+sx.r>>1;
    if(l<=mid)add(x<<1,l,r);
    if(r>mid)add(x<<1|1,l,r);
    sx.w=max(lc.w,rc.w);
}
int ask(int x,int l,int r){
    if(l<=sx.l&&sx.r<=r){
        return sx.w;
    }
    if(sx.g)down(x);
    int mid=sx.l+sx.r>>1,ans=0;
    if(l<=mid)ans=max(ans,ask(x<<1,l,r));
    if(r>mid)ans=max(ans,ask(x<<1|1,l,r));
    return ans;
}
int main(){    
//    freopen("ex_leader2.in","r",stdin);
    n=read();
    F(i,1,n)a[i]=read(),b[i]=read(),c[i]=a[i],c[i+n]=b[i];
    sort(c+1,c+n*2+1);
    lmt=unique(c+1,c+n*2+1)-c-1;
    biu(1,1,lmt);
    int x=0,ans=0;
    F(i,1,n){    
        a[i]=lower_bound(c+1,c+lmt+1,a[i])-c;
        b[i]=lower_bound(c+1,c+lmt+1,b[i])-c;
        x=ask(1,b[i]+1,lmt)+1;
        ans=max(ans,x);
        if(b[i]>=a[i]){
            upd(1,a[i],x);
        }
        else{
            x=ask(1,a[i],lmt)+1;
            upd(1,a[i],x);
            add(1,b[i]+1,a[i]-1);
        }
    }
    printf("%d\n",ans);
}
il int read(){
    int s=0;char ch;
    while(ch=getchar(),!isdigit(ch));
    for(;isdigit(ch);s=s*10+(ch^48),ch=getchar());
    return s;
}
/*
g++ 1.cpp -g
./a.out
5
2 5
3 3
7 2
8 3
4 5
*/
View Code
#include<bits/stdc++.h>
#define F(i,a,b) for(rg int i=a;i<=b;++i)
#define LL long long
#define il inline
#define rg register
#define pf(a) printf("%d ",a)
#define phn puts("")
using namespace std;
int read();
int n,m;
#define N 200010
int c[N],to[N<<1],fir[N<<1],head[N],cnt;
il void lian(int x,int y){
    to[++cnt]=y;fir[cnt]=head[x];head[x]=cnt;
}    
vector<pair<int,int> >que[N];
#define fst first
#define scd second
int T[N],ans[N],w[N],sta[N],top,vis[N];
int son[N],sz[N],dep[N],mxd;
void gets(int x,int d){
    sz[x]=1;dep[x]=d;mxd=max(mxd,d);
    for(int i=head[x];i;i=fir[i]){
        int v=to[i];
        gets(v,d+1);
        sz[x]+=sz[v];
        if(sz[son[x]]<sz[v])son[x]=v;
    }
}
il void jia(rg int x,int p){
    for(;x<=mxd;x+=x&-x)w[x]+=p;
}
il int ask(rg int x){int s=0;for(;x;x-=x&-x)s+=w[x];return s;}
void sear(int x){
    if(T[c[x]]==-1||T[c[x]]>dep[x]){
        if(T[c[x]]!=-1)jia(T[c[x]],-1);
        else sta[++top]=c[x];
        T[c[x]]=dep[x];jia(dep[x],1);
    }
    for(int i=head[x];i;i=fir[i])sear(to[i]);
}
void dfs(int x){
    int v;
    for(int i=head[x];i;i=fir[i]){
        v=to[i];
        if(v!=son[x])dfs(v);
        while(top)jia(T[sta[top]],-1),T[sta[top]]=-1,--top;
    }
    if(son[x])dfs(son[x]);
    if(T[c[x]]!=-1)jia(T[c[x]],-1);
    else sta[++top]=c[x];
    T[c[x]]=dep[x];jia(dep[x],1);
    for(int i=head[x];i;i=fir[i])if(to[i]!=son[x])sear(to[i]);
    int ed=que[x].size()-1;
    F(i,0,ed){
        ans[que[x][i].scd]=ask(min(dep[x]+que[x][i].fst,mxd));
    }
}    
int main(){    
//    freopen("xb.in","r",stdin);    freopen("2.out","w",stdout);
    memset(T,-1,sizeof(T));
    n=read();m=read();F(i,1,n)c[i]=read();
    int x,d;
    F(i,2,n){
        x=read();lian(x,i);
    }
    F(i,1,m)x=read(),d=read(),que[x].push_back(make_pair(d,i));
    gets(1,1);
    mxd+=5;
    dfs(1);
    F(i,1,m)printf("%d\n",ans[i]);
}
il int read(){
    int s=0;char ch;
    while(ch=getchar(),!isdigit(ch));
    for(;isdigit(ch);s=s*10+(ch^48),ch=getchar());
    return s;
}
/*
g++ 2.cpp -g
./a.out
7 3
2 2 1 2 1 1 1 
1 1 2 2 3 3 
4 41
4 24
5 2
g++ 2.cpp -g
time ./a.out
5 5
1 3 3 2 2
1 1 3 3
1 0
1 3
1 2
2 1
3 2
*/
View Code
#include<bits/stdc++.h>
#define F(i,a,b) for(rg int i=a;i<=b;++i)
#define LL long long
#define il inline
#define rg register
#define pf(a) printf("%d ",a)
#define phn puts("")
using namespace std;
#define int LL
int read();
char s[3005];
int n,len;
int las[3005],head[30],f[3005][3005];
const int mod=998244353;
signed main(){    
    scanf("%s",s+1);
    n=strlen(s+1);
    len=read();
    F(i,1,n)las[i]=head[s[i]-'a'],head[s[i]-'a']=i;
    f[0][0]=1;
    F(i,1,n){
        f[i][0]=1;
        F(j,1,len){
            f[i][j]=(las[i]?(f[i-1][j]+f[i-1][j-1]-f[las[i]-1][j-1]):
            (f[i-1][j]+f[i-1][j-1]))%mod;
        }
    }
    printf("%lld\n",(f[n][len]+mod)%mod);
}
il int read(){
    int s=0;char ch;
    while(ch=getchar(),!isdigit(ch));
    for(;isdigit(ch);s=s*10+(ch^48),ch=getchar());
    return s;
}
/*
g++ 3.cpp -g
./a.out
ppsdvnvwnczwptuqbfwo
9

*/
View Code

 

T0:

0, to pay the exam papers,

However geese. . .

Cross-file write freopen () !!!!!

Documents: 1, fight freopen2, three folders, file names,
but fortunately not a regular exam. . . . . .

1, a point of view on the topic description T1 is water problem, just go to T1. But T3 is relatively the easiest.

T1 see DP is a data structure maintenance, but called Fenwick tree found DP wrong, has been pushing DP, very confusing.

He spent a half hours, leaving the write T2. T2 violence is better written.

Go back and look at T1, push DP, did not write the data structure of DP, finally right. Then add to the tree line, and finally the A.

2, sub-section did not take full. These two exams are.

The last remaining part of the time should first get full points, to go try to play a positive solution.

When I read the title of what to look at a portion of the points.

3, open question correct order: T3, T1, T2.

T1:

DP。

Set F [i] [j] denotes the i-th processed crystal, the maximum number of crystal has been selected as the smallest j destroyed.

Ai and bi discuss the relationship between size, blind transfer **

experience:

1, the data structure to maintain DP to DP write first, look right, go play data structure,

2, it can not be used Fenwick tree maintenance, tree line only thing more later. For example, while a single point and updates the maximum interval plus.

to sum up:

DP unfamiliar skills. And relatively blind, you should write dp look right.

T2:

Non-positive solution can be used offline water heuristic past.

Tree heuristic + Fenwick tree. Heuristic maintain this color from the current point nearest deep. (Should've been on the meaning, but here maintains global deep, otherwise poor maintenance, can not be shared)

Fenwick tree deep as the number of index maintenance.

Portion may be divided or combined dfs sequence segment tree team Mo +

T3:

There are psychological fear of difficulty for T3. But sometimes the easiest T3.

1, noip no suffix array.

2, did not play a part in 10 minutes. But it is a special sentence. Pay attention next time when I wanted to read the title section points.

3, the number of program sequences considered legitimate DP

4, DP knowledge is not enough, there is no regularity seen.

5, the main take up too much time T1, T3 no time.

Compare miss violence, dfs enumeration + hash or trie. Enumeration is the number of the complexity of the combination.

The data range, the complexity of a look should be S ^ 2
disposed F [i] [j] denotes the i-th position before the processed strings, ⻓ degree j of the number of essentially different sequences.
Transfer consider adding a trailing character, direct idea of f [i] [j] = f [i-1] [j] + f [i] [j-1]
, however we will count weight, consider count heavy portion Save out.
Operators must heavy portion is a [i] is the end of the string.
Therefore, the position set a [i] is the last time p, then the end of the string and p-calculated weight of the string-one correspondence.

Ending p, j transferred to a number length is f [p-1] [j -1]
Pretreatment las showing each point, the transfer equation: f [i] [j] = f [i-1] [ j] + f [i] [ j-1] -f [p-1] [j-1]

For a [i] special consideration first appears, do not lose weight.
.

Guess you like

Origin www.cnblogs.com/seamtn/p/11487522.html
40