The number of colors (block?)

Topic Portal


I feel that this question is not necessary to effect a nonsense title, futile.

Violence had lost, wiping the sides.

The main card is to talk about this question I often used.

First, 0,1 flag bit operation I used, bitwise operators run than normal +, -, ×, ÷, true, false fast.

Secondly, I used

while(isspace(op=fgetc(stdin)));
ungetc(op,stdin);

cpp

Eat characters.

Personal feeling than while fast.

Quick read of course essential, fast read bit computing faster.

inline int read()
{
    short x=0;
    char ch=getchar();
    while(ch<'0'||ch>'9')
        ch=getchar();
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x;
}

cpp

These things had enough card data over the water Luo Valley, but still suggest that you beat a positive solution.

In addition, the students learned today from this:

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++)

cpp

 Seems to be capable of a lot faster, but requires caution, I also use unskilled, this will not do much to explain, is not responsible for problems.


Code time:

#include<cstdio>
#include<cstring>
#include<cctype>
int a[10001],x,y,ans;
int wzc[1000001];
char op;
inline int read()
{
    int x=0;
    char ch=getchar();
    while(ch<'0'||ch>'9')
        ch=getchar();
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x;
}
int main()
{
    x=read();
    for(register int i=0;i<=x;++i)a[i]=read();
    while(a[0]--)
    {
        while(isspace(op=fgetc(stdin)));
        ungetc(op,stdin);
        on getcharO = ();
        x=read();
        y=read();
        if(op=='Q')
        {
            ans=0;
            memset(wzc,0,sizeof(wzc));
            for(register int i=x;i<=y;++i)
                ans+=wzc[a[i]]^1,wzc[a[i]]|=1;
            printf("%d\n",ans);
        }
        else a[x]=y;
    }
    return 0;
}

 cpp

Of course, the card is often code, ha ha ha


 

rp ++

Guess you like

Origin www.cnblogs.com/wzc521/p/11018827.html