8.13 discipline in training Day13

T1rank

Description

Closing & three school exam results, small R after reading achievement was sad before small and small R h are watching, a total of n (n <= 5 * 10 ^ 6) students, the i-th student has a total score of Xi (0 <= Xi <= 10 ^ 5), since his ranking is the inverse of k (1 <= k <= n) th, the little R want to know who score lower than his (including grades like him) classmates the results, so let him not so sad.

Input

The first row, n and k, n students expressed, small R K penultimate row.
The second row, a non-negative integer n, denotes the n student performance.

Output

Row, a total number of k, from small to large outputs. (The same result has different rank)

Sample Input

5 3
1 1 2 2 3

Sample Output

1 1 2

Examination room ideas / positive solution

Title simply means that you want to sort it, but the range of available observational data, better use barrels row here, so gone.

Code

#include<cstdio>
#include<algorithm>

int n,k,v,sl,zx,cc;
int book[100010];

int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&v);
        book[v]++;
    }
    for(int i=0;i<=100000;i++)
    {
        cc=sl;
        sl+=book[i];
        if(sl>=k)
        {
            zx=i;
            break;
        }
    }
    for(int i=0;i<zx;i++)
        if(book[i])
            for(int j=1;j<=book[i];j++)
                printf("%d ",i);
    for(int i=cc;i<k;i++)
        printf("%d ",zx);
    return 0;
}

T2seek

Description

As the saying goes, "not as lucky good name," little h ready to give his pet dog from the new name, so he put some English full name written down, written in a long line of string, a small h that name if is a good name, then the name in this string is both a prefix and a suffix, that is, the name began to be matched from the front, began to be matched from the back, such as abc in abcddabc in both a prefix, also the suffix, but ab is not but as long as 4 * 10 ^ 5 characters make small h almost fainted, to give his dog a good name, a small h to you for help, and he asked all of the length of the good name you want to output to both .

Input

Line, the character string to be processed (all lowercase).

Output

Several digital line, from small to large output, indicates the length of a good name.

Sample Input

abcddabc

Sample Output

3 8

Examination room ideas / positive solution

Very bare KMP, needs no explanation. .

Code

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int len,k,num;
int Next[400040],zx[400040];
char ch[400040];

int main()
{
    scanf("%s",ch+1);
    len=strlen(ch+1);
    for(int i=2;i<=len;i++)
    {
        while(k>0 && ch[k+1]!=ch[i])
            k=Next[k];
        if(ch[k+1]==ch[i])
            k++;
        Next[i]=k;
    }
    k=Next[len];
    while(k>0)
    {
        zx[++num]=k;
        k=Next[k];
    }
    for(int i=num;i>=1;i--)
        printf("%d ",zx[i]);
    printf("%d",len);
    return 0;
}

T3pot

Description

This holiday season, small h in the yard planted many flowers, they huddled in a circle, from 1..n number (n <= 100000), has a preference for small h value of each flower xi, (- 1000 < = xi <= 1000), now I feel so small h immutable very boring, so he made m (m <= 100000) a change, every time the first disk flowers into preference value ki di flowers, and then to a small h you tell him, in the wreath, the continuous maximum preference value is.

Input

The first row, n, the number of pots
second row, the number n, the preference value for each potted.
Third row: m, the number of changes of
the m rows, each two numbers ki and di.

Output

M rows, each row corresponds to a change, as a continuous maximum preference value, and can not be selected from the entire lap. (Note: in the circle to find)

Sample Input

5
3 -2 1 2 -5
4
2 -2
5 -5
2 -4
5 -1

Sample Output

4
4
3
5

Examination room ideas

Hit a 30 points during the examination of violence, okay, not necessarily hang up.

Correct

I later learned that positive solutions tears fall. Wow, more than a simple I thought. First, the maximum and minimum and maximum and actually the entire sub-segment and sub-segment by subtracting consecutive sub-segments in a continuous and takes a maximum value in the sub-ring segments. (This is what I do not know eh.) And then maintain it at a tree line just add, after finished, in 10 minutes directly to this topic A, and even compile all right, did not expect positive solution exams, pity .

Code

#include<cstdio>
#include<algorithm>
using namespace std;

int n,m,zx,d;
struct TREE
{
    int l,r;
    int sum;
    int lmin,rmin,smin;
    int lmax,rmax,smax;
}tree[100010*8];

void Update(int k)
{
    tree[k].sum=tree[k*2].sum+tree[k*2+1].sum;
    tree[k].lmin=min(tree[k*2].lmin,tree[k*2].sum+tree[k*2+1].lmin);
    tree[k].rmin=min(tree[k*2+1].rmin,tree[k*2].rmin+tree[k*2+1].sum);
    tree[k].lmax=max(tree[k*2].lmax,tree[k*2].sum+tree[k*2+1].lmax);
    tree[k].rmax=max(tree[k*2+1].rmax,tree[k*2].rmax+tree[k*2+1].sum);
    tree[k].smin=min(tree[k*2].rmin+tree[k*2+1].lmin,min(tree[k*2].smin,tree[k*2+1].smin));
    tree[k].smax=max(tree[k*2].rmax+tree[k*2+1].lmax,max(tree[k*2].smax,tree[k*2+1].smax));
}

void Build(int L,int R,int k)
{
    int Mid=(L+R)/2;
    tree[k].l=L;tree[k].r=R;
    if(L==R)
    {
        scanf("%d",&tree[k].sum);
        tree[k].lmin=tree[k].rmin=tree[k].smin=tree[k].lmax=tree[k].rmax=tree[k].smax=tree[k].sum;
        return;
    }
    Build(L,Mid,k*2);
    Build(Mid+1,R,k*2+1);
    Update(k);
}

void Work(int L,int R,int k)
{
    int Mid=(L+R)/2;
    if(L==R)
    {
        tree[k].sum=tree[k].lmin=tree[k].rmin=tree[k].smin=tree[k].lmax=tree[k].rmax=tree[k].smax=d;
        return;
    }
    if(zx<=Mid)
        Work(L,Mid,k*2);
    if(Mid<zx)
        Work(Mid+1,R,k*2+1);
    Update(k);
}

int main()
{
    scanf("%d",&n);
    Build(1,n,1);
    scanf("%d",&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&zx,&d);
        Work(1,n,1);
        printf("%d\n",max(tree[1].smax,tree[1].sum-tree[1].smin));
    }
    return 0;
}

T4 game show

Description

There are three ranks, namely A, B, C. N has a game show, the i-th game play, the team can get a score of A A [i], B team can get a score of B [i], C team can get a score of C [i]. Due to limited time, each program may not be able to play, so the decision from the n-show host game shows and programs to pick out at least k program (the selected program, regardless of order), so that team A wins. A team can be the winner of that total score total score than team B team A to be higher, but also than the team total score of C is higher. Show host how many different selection schemes?

Input

The first line, two integers n and k. 

Second row, n-integers, respectively, A [1], A [2 ], A [3] ... A [n].

Third row, n-integers, namely B [1], B [2 ], B [3] ... B [n].

Fourth row, n-integers, are C [1], C [2 ], C [3] ... C [n].

Output

An integer representing the number of different selection scheme.

Sample Input

3 2
1 1 2
1 1 1
1 1 1

Sample Output

3 
[explain] Sample

program: Select program 1 and program 3.
Option II: Select program 2, and program 3.
Program III: Select program 1, program 2, program 3.

Data Constraint

Data for 40%, 2 <= n <= 20 .

Data for 100%, 2 <= n <= 34 , 1 <= k <= min (n, 7), 1 <= A [i], B [i], C [i] <= 10 ^ 9.

Examination room ideas

No Guannameduo exam, anyway, violence is the right thing.

Correct

This problem seems to be using the binary search is then maintained in an array plus a tree or tree line. (A bit sleepy, it is unknown that I believe that smart readers will be seen trekking in the code I wanted to say.)

Code

#include<cstdio>
#include<algorithm>
#define lowbit(x) x&-x
#define LL long long
#define NAME "show"
using namespace std;

LL n,kk,ans1,ans2,Count,t,zz;
LL a[55],b[55],c[55],tot[2],sz[262160];

struct thm1
{
    LL x,y;
}q[2][131080];

struct thm2
{
    LL x;
    LL xb;
    LL mark;
}zx[262160];

void Open()<%freopen(NAME".in","r",stdin);freopen(NAME".out","w",stdout);%>

void Dfs1(LL x,LL k,LL suma,LL sumb,LL sumc)
{
    if(x==kk)
        return;
    if(suma>sumb && suma>sumc)
        ans2++;
    for(LL i=k;i<=n;i++)
        Dfs1(x+1,i+1,suma+a[i],sumb+b[i],sumc+c[i]);
}

void Dfs2(LL k,LL sumab,LL sumac,LL pd,LL end)
{
    q[pd][++tot[pd]].x=sumab;
    q[pd][tot[pd]].y=sumac;
    for(LL i=k;i<=end;i++)
        Dfs2(i+1,sumab+(a[i]-b[i]),sumac+(a[i]-c[i]),pd,end);
}

void init()
{
    scanf("%lld%lld",&n,&kk);
    for(LL i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    for(LL i=1;i<=n;i++)
        scanf("%lld",&b[i]);
    for(LL i=1;i<=n;i++)
        scanf("%lld",&c[i]);    
}

bool cmp1(thm2 a,thm2 b)
<%return a.x<b.x;%>
bool cmp2(thm1 a,thm1 b)
<%return a.y<b.y;%>
bool cmp3(thm1 a,thm1 b)
<%return a.y>b.y;%>

void Update(LL x)
{
    while(x<=t)
    {
        sz[x]+=1;
        x+=lowbit(x);
    }
}

LL Sum(LL x)
{
    LL sum=0;
    while(x>=1)
    {
        sum+=sz[x];
        x-=lowbit(x);
    }
    return sum;
}

int main()
{
    Open();
    init();
    Dfs1(0,1,0,0,0);
    Dfs2(1,0,0,0,n/2);
    Dfs2(n/2+1,0,0,1,n);
    for(LL i=1;i<=tot[0];i++)
    {
        zx[++Count].x=q[0][i].x;
        zx[Count].xb=i;
        zx[Count].mark=0;
    }
    for(LL i=1;i<=tot[1];i++)
    {
        zx[++Count].x=-q[1][i].x;
        zx[Count].xb=i;
        zx[Count].mark=1;
    }
    sort(zx+1,zx+1+Count,cmp1);
    zx[0].x=-1e18;
    for(LL i=1;i<=Count;i++)
    {
        if(zx[i].x!=zx[i-1].x)
            t++;
        q[zx[i].mark][zx[i].xb].x=t;
    }    
    sort(q[0]+1,q[0]+1+tot[0],cmp2);
    sort(q[1]+1,q[1]+1+tot[1],cmp3);
    zz=1;
    for(LL i=1;i<=tot[0];i++)
    {
        while(zz<=tot[1] && q[0][i].y+q[1][zz].y>0)
        {
            Update(q[1][zz].x);
            zz++;
        }
        ans1+=Sum(q[0][i].x-1);
    }
    printf("%lld",ans1-ans2);
    return 0;
}

to sum up

Today is not that bad of it, at least violence all right, tomorrow to continue filling it!

 

Left 87 days from NOIp2019 Festival

 

Guess you like

Origin www.cnblogs.com/Thm-V/p/11360769.html