8.10 NOIP analog test 16 Blue + Weed + Drink

T1 Blue

Greedy, every time jump jump can jump the farthest place, and put him to skip 0, find the location of each half, has been dancing on the line, if they can jump position is the current position or location than the current also small (array now stay in this piece of stone, half is to get the current position of -1 would be less than the current position. However, the impact of 0, while the fallback is very slow, so the switch to support the set earse operations, you can water over him (which is the difference between T40 and AC !!!)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
#include<algorithm>
using namespace std;
int T,n,m,d,l;
set<int>st;
set<int>::iterator it;
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*10+cc-'0';cc=getchar();}
    return aa*bb;
}
int main()
{
    T=read();
    while(T--){
        st.clear();
        n=read();m=read();d=read(),l=read();
        bool flag=0,flag1=0;
        for(int i=1;i<=n;i++){
            st.insert(read());
        }
        st.insert(l);st.insert(0);
        if(d==l){
            puts("Excited");
            continue;
        }
        for(int i=1;i<=m;i++){
            int pos=0;
            while(pos<l){
                if(pos+d>=l) break;
                it=st.upper_bound(pos+d);
                if(*(--it)<=pos){
                    flag=1;
                    break;
                }
                pos=*it;
                st.erase(it);
            }
            if(flag){
                printf("%d\n",i-1);
                flag1=1;
                break;
            }
        }
        if(flag1) continue;
        puts("Excited");
    }
    return 0;
}
blue

 

T2 Weed

Courseware koala's seniors talked about, but I will not.

Is a magical tree line, with a magical cal function, we could happily get 100 points, good results!

In time index, to build a segment tree, the tree maintenance four values ​​sum, del, cnt, las

sum: all current operations within the remaining sum of the interval after adding ans Ziglar deleted = t [1] .sum

del: The current range but also forward (the interval before a current section) deleted how many layers

cnt: The current range is deleted after the interval own left many layers

las: Left and right after his son was deleted with the del son How much is left (only son left for maintenance)

Cal function of the role is to calculate the value of las, x maintenance information, the son left and right will be deleted when the son update, in order to maintain the accuracy of the information section, the need to remove some of the value of the left and right with his son's son del, delete, etc. we just saved in the segment information in, without making changes to the following node (because this is the section information). cnt left and right son of the son of del several relationships below, can be dealt with separately

1.l.cnt <r.del left son is not deleted, then left as a direct son does not exist, the rest of the calculated sum worth of value to x

Deletion does not exist 2.r.del == 0 Right son, a direct merger

3.lrcnt> r.del left son of the right son is enough to delete the right son, return l.las + cal (lr, r.del)

4.lrcnt <r.del left and right son son son is not enough to delete the right, then go left to continue his son's son left in delete return cal (ll, r.del-lrcnt + lrdel) plus remember right son left his son He left his son left his son del

5.lrcnt == r.del son left his son the right to delete just enough direct return l.las

Modifying operation is actually a single point of the segment tree modify operation, a change value, the information update other sections will be up, and finally t [1] .sum is the answer.

/ * SUM: deleted after the interval sum 
del: how many current range to forward delete 
cnt: delete the current interval after how many plus operating 
las: son left his son the right to be deleted after the sum * / 
# the include <the iostream> 
#include <CString> 
#include <cstdio>
 the using  namespace STD;
 struct Node 
{ 
    int L, R & lt, SUM, del, CNT, Las; 
} T [ 800.1 thousand ];
 int n-, m, opt, V;
 int Read () 
{ 
    int AA = 0 , = BB . 1 ; char CC = getchar ();
     the while (CC> ' . 9 ' || CC < '0'){if(cc=='-') bb=-1;cc=getchar();}
    while(cc<='9'&&cc>='0'){aa=aa*10+cc-'0';cc=getchar();}
    return aa*bb;
}
int cal(int x,int num)
{
    if(t[x*2+1].cnt>num) return t[x*2].las+cal(x*2+1,num);
    if(t[x*2+1].cnt<num) return cal(x*2,num-t[x*2+1].cnt+t[x*2+1].del);
    if(t[x*2+1].cnt==num) return t[x*2].las;
}
void update(int x)
{
    if(!t[x*2+1].del){
        t[x].sum=t[x*2].sum+t[x*2+1].sum;
        t[x].del=t[x*2].del;
        t[x].cnt=t[x*2].cnt+t[x*2+1].cnt;
        t[x*2].las=t[x*2].sum;
        return;
    }
    if(t[x*2].cnt<=t[x*2+1].del){
        t[x].sum=t[x*2+1].sum;
        t[x].del=t[x*2].del+t[x*2+1].del-t[x*2].cnt;
        t[x].cnt=t[x*2+1].cnt;
        t[x*2].las=0;
        return;
    }
    t[x*2].las=cal(x*2,t[x*2+1].del);
    t[x].sum=t[x*2].las+t[x*2+1].sum;
    t[x].del=t[x*2].del;
    t[x].cnt=t[x*2+1].cnt+t[x*2].cnt-t[x*2+1].del;
}
void build(int x,int l,int r)
{
    t[x].l=l;t[x].r=r;
    if(l==r){
        opt=read();
        if(opt==0){
            t[x].sum=read();
            t[x].del=0;
            t[x].cnt=1;
            t[x].las=0;
        }
        else{
            t[x].sum=0;
            t[x].del=read();
            t[x].cnt=0;
            t[x].las=0;
        }
        return;
    }
    int mid=(l+r)>>1;
    build(x*2,l,mid);
    build(x*2+1,mid+1,r);
    update(x);
}
void change(int x,int pos)
{
    if(t[x].l==t[x].r&&t[x].l==pos){
        if(opt==0){
            t[x].sum=v;
            t[x].del=0;
            t[x].cnt=1;
            t[x].las=0;
        }
        else{
            t[x].sum=0;
            t[x].del=v;
            t[x].cnt=0;
            t[x].las=0;
        }
        return;
    }
    int mid=(t[x].l+t[x].r)>>1;
    if(pos<=mid) change(x*2,pos);
    else change(x*2+1,pos);
    update(x);
}
int main()
{
    n=read();m=read();
    build(1,1,n);
    for(int i=1,j;i<=m;i++){
        j=read();opt=read();v=read();
        change(1,j);
        printf("%d\n",t[1].sum);
    }
    return 0;
}
Weed

 

T3 Drink

Survive circle around the first, and then after the turn should place "shop" up, T30 with the queue memory, and an array of char deposit storage table type (only 1 ~ 9) to the T60, T80 adjust the cycle sequence , register deleted, for the card can be changed while the T90, finally fast read a little change, on the a

On the word, crazy cards can often A.

However, positive solutions are not so long. . . I do not know the specific long-sawed

The following is a positive solution:

Drink:

Rome used to seeing the sound of the kids will know r hair l sound, title name: D Link.

Each modification will change O (2 N ^) th value of the position of the two-dimensional positive direction on a plane is not defined, and therefore can not use a conventional data structure.

What amount of change in things is O (N) level of it?

If every point, as a man, his head facing a certain direction . They were recorded this man who is around, the direction is, respectively , then each rotation change just a square edge on the value and direction of all points.

This term at least we found a change in the amount of O (N) level stuff it ( although the variable direction or O (N ^ 2) ) .

Notes that , we do not need to really know each point of direction, we just need the right to maintain four to value all around . Since each direction of the point is known in the direction of the adjacent counted out point!

Each point indeed there is a direction , but we do not have records do not directly change it every time as long as the right to modify the boundary values, the entire rectangular orientation changes automatically.

Solve it!

Complexity of O (Q * N), the constant is slightly larger.

 

#include<iostream>
#include<cstdio>
const int L=1<<20|1;
char buffer[L],*S,*T;
#define getchar() ((S==T&&(T=(S=buffer)+fread(buffer,1,L,stdin),S==T))?EOF:*S++)
using namespace std;
char a[2010][2010],c,b[8010];
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^48);cc=getchar();}
    return aa*bb;
}
int main()
{
    int n,m,qq,num;
    n=read(),m=read(),qq=read();
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++){
            c=getchar();
            while(c<'0'||c>'9')  c=getchar();
            a[i][j]=c;
        }
    int x,y,l,i=1,j;
    while(i<=qq){
        x=read();y=read();l=read();
        while(l>=2){
            num=0;
            j=0;while(j<l) b[++num]=a[x][y+j],++j;
            j=1;while(j<l) b[++num]=a[x+j][y+l-1],++j;
            j=l-2;while(j>=0) b[++num]=a[x+l-1][y+j],--j;
            j=l-2;while(j>=1) b[++num]=a[x+j][y],--j;
            
            j=l-2;while(j>=1) a[x][y+j]=b[num--],--j;
            j=0;while(j<=l-2) a[x+j][y]=b[num--],++j;
            j=0;while(j<=l-2) a[x+l-1][y+j]=b[num--],++j;
            j=l-1;while(j>=0) a[x+j][y+l-1]=b[num--],--j;
            x++,y++;l-=2;
        }
        i++;
    }
    i=1;
    while(i<=n){
        j=1;
        while(j<=m){
            putchar(a[i][j]),putchar(' ');
            j++;
        }
        puts("");
        i++;
    }
    return 0;
}
Drink (+ cards often violent)

 

 

This question is short test point is very water, T1T3 violence can water before, but the sample is too inhumane to put a computer card collapse 34 times.

 

Guess you like

Origin www.cnblogs.com/jrf123/p/11333106.html
Recommended