"CSP-S simulation game" 2019 second field


Examination of this data feel water.
\ (Tl \) sign is not explained, \ (T2 \) desired \ (50pts \) Results \ (100 pts \) , \ (T3 \) always ... do not
___

The notation T1 Jam

topic

click here

Examination room thinking (positive solutions)

In fact, not much to say, look to the law, take a look at the code.

#include<cstdio>
// #define FILEOI
#define rep(i,__l,__r) for(int i=__l,i##_end_=__r;i<=i##_end_;++i)
#define dep(i,__l,__r) for(int i=__l,i##_end_=__r;i>=i##_end_;--i)
#define cg (c=getchar())
template<class T>inline void qread(T& x){
    x=0;char c;bool f=0;
    while(cg<'0'||'9'<c)if(c=='-')f=1;
    for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
    if(f)x=-x;
}
template<class T,class... Args>inline void qread(T& x,Args&... args){qread(x),qread(args...);}
inline int qread(){
    int x=0;char c;bool f=0;
    while(cg<'0'||'9'<c)if(c=='-')f=1;
    for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
    return f?x:-x;
}
#undef cg
template<class T>inline T Max(const T x,const T y){return x>y?x:y;}
template<class T>inline T Min(const T x,const T y){return x<y?x:y;}
template<class T>inline T fab(const T x){return x>0?x:-x;}
template<class T>void fwrit(T x){
    if(x<0)return (void)(putchar('-'),fwrit(-x));
    if(x>10)fwrit(x/10);
    return (void)(putchar(x%10^48));
}

const int MAXW=25;
int s,t,w,num[(MAXW<<2)+5],T=5;
char sn[(MAXW<<2)+5];

inline void init(){
    qread(s,t,w);
    scanf("%s",sn+1);
    rep(i,1,w)num[i]=sn[i]-'a'+1;
}

inline void putNum(){
    for(int i=1;i<=w;++i)printf("%c",num[i]+'a'-1);
    putchar('\n');
}

inline void addOne(){
    bool f=true;
    for(int i=w;i>=1;--i)if(num[i]<t-w+i){
        ++num[i],f=false;
        for(int j=i+1;j<=w;++j)num[j]=num[j-1]+1;
        break;
    }
    if(f)return;
    putNum();
}

signed main(){
#ifdef FILEOI
    freopen("number.in","r",stdin);
    freopen("number.out","w",stdout);
#endif
    init();
    while(T--)addOne();
    return 0;
}

T2 "TJOI / HEOI2016" Sort

topic

click here

Examination room ideas (false positive solutions)

Direct see \ (50 \% \) range of data discovery interval bucket sort may be used, the time complexity \ (O (nm) \) .

#include<cstdio>
// #define FILEOI
#define rep(i,__l,__r) for(int i=__l,i##_end_=__r;i<=i##_end_;++i)
#define dep(i,__l,__r) for(int i=__l,i##_end_=__r;i>=i##_end_;--i)
#define cg (c=getchar())
template<class T>inline void qread(T& x){
    x=0;char c;bool f=0;
    while(cg<'0'||'9'<c)if(c=='-')f=1;
    for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
    if(f)x=-x;
}
template<class T,class... Args>inline void qread(T& x,Args&... args){qread(x),qread(args...);}
inline int qread(){
    int x=0;char c;bool f=1;
    while(cg<'0'||'9'<c)if(c=='-')f=0;
    for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
    return f?x:-x;
}
#undef cg
template<class T>inline T Max(const T x,const T y){return x>y?x:y;}
template<class T>inline T Min(const T x,const T y){return x<y?x:y;}
template<class T>inline T fab(const T x){return x>0?x:-x;}
template<class T>void fwrit(T x){
    if(x<0)return (void)(putchar('-'),fwrit(-x));
    if(x>10)fwrit(x/10);
    return (void)(putchar(x%10^48));
}

const int MAXN=1e5;

int n,m,q,a[MAXN+5],t[MAXN+5];

inline void init(){
    qread(n,m);
    rep(i,1,n)qread(a[i]);
}

inline void getOperation(){
    int op,l,r,li,ri;
    while(m--){
        li=n,ri=0;
        qread(op,l,r);
        rep(i,l,r)++t[a[i]],li=Min(li,a[i]),ri=Max(ri,a[i]);
        if(op==0){
            rep(i,l,r){
                while(t[li]==0)++li;
                a[i]=li,t[li]=0;
            }
        }
        else if(op==1){
            rep(i,l,r){
                while(t[ri]==0)--ri;
                a[i]=ri,t[ri]=0;
            }
        }
    }
    printf("%d\n",a[qread()]);
}

signed main(){
#ifdef FILEOI
    freopen("sort.in","r",stdin);
    freopen("sort.out","w",stdout);
#endif
    init();
    getOperation();
    return 0;
}

Expect to score only \ (50pts \) , but the data measured out, was able to \ (A \) away ... so called pseudo-positive solutions ...

Correct

We found that, for a \ (X \) , will be less than \ (X \) is replaced by the number \ (0 \) , greater than or equal \ (X \) is replaced by the number \ (1 \) Thereafter, the resulting ordering in fact, the result is the same.
But this has only flaw is that we only know that the last \ (q \) the number of locations is \ (0 \) or \ (1 \) .
In fact, a good solution, half the \ (x \) can be.
Here first nominal attached
std version

#include <cstdio>
#include <cstring>
#include <cctype>
#define lc o << 1
#define rc o << 1 | 1
#define mid (l + r) / 2
using namespace std;

const int N = 100010;
int n, m, p;
int T[4 * N], lazy[4 * N];    // segment tree
int a[N], ch[N], L[N], R[N];  // the information by reading

inline int read() {
    char ch = getchar();
    int x = 0;
    while (!isdigit(ch)) ch = getchar();
    while (isdigit(ch)) {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x;
}

inline void build(int o, int l, int r, int x) {
    if (l == r) {
        T[o] = a[l] >= x;
        lazy[o] = 0;
        return;
    }
    build(lc, l, mid, x);
    build(rc, mid + 1, r, x);
    T[o] = T[lc] + T[rc];
    lazy[o] = 0;
}

inline void pushdown(int o, int l, int r) {
    if (!lazy[o])
        return;
    lazy[lc] = lazy[rc] = lazy[o];
    if (lazy[o] == 1) {
        T[lc] = mid - l + 1;
        T[rc] = r - mid;
    } else
        T[lc] = T[rc] = 0;
    lazy[o] = 0;
}

inline int query(int o, int l, int r, int x, int y) {
    if (x <= l && y >= r)
        return T[o];
    if (x > r || y < l)
        return 0;
    pushdown(o, l, r);
    return query(lc, l, mid, x, y) + query(rc, mid + 1, r, x, y);
}

inline int queryPoint(int o, int l, int r, int x) {
    if (l == x && r == x)
        return T[o];
    pushdown(o, l, r);
    if (x <= mid)
        return queryPoint(lc, l, mid, x);
    else
        return queryPoint(rc, mid + 1, r, x);
}

inline void update(int o, int l, int r, int x, int y, int val) {
    if (x <= l && y >= r) {
        T[o] = val * (r - l + 1);
        lazy[o] = val ? 1 : -1;
        return;
    }
    if (x > r || y < l)
        return;
    pushdown(o, l, r);
    update(lc, l, mid, x, y, val);
    update(rc, mid + 1, r, x, y, val);
    T[o] = T[lc] + T[rc];
}

inline bool check(int x) {
    build(1, 1, n, x);
    for (int i = 1; i <= m; i++) {
        int cnt1 = query(1, 1, n, L[i], R[i]);
        if (ch[i] == 0) {
            update(1, 1, n, R[i] - cnt1 + 1, R[i], 1);
            update(1, 1, n, L[i], R[i] - cnt1, 0);
        } else {
            update(1, 1, n, L[i], L[i] + cnt1 - 1, 1);
            update(1, 1, n, L[i] + cnt1, R[i], 0);
        }
    }
    return queryPoint(1, 1, n, p);
}

int main() {
    freopen("sort.in","r",stdin);
    freopen("sort.out","w",stdout);
    n = read();
    m = read();
    for (int i = 1; i <= n; i++) a[i] = read();
    for (int i = 1; i <= m; i++) {
        ch[i] = read();
        L[i] = read();
        R[i] = read();
    }
    p = read();
    int ll = 1, rr = n, midd, ans;
    while (ll <= rr) {
        midd = (ll + rr) >> 1;
        if (check(midd))
            ans = midd, ll = midd + 1;
        else
            rr = midd - 1;
    }
    printf("%d\n", rr);
    return 0;
}

My version

#include<cstdio>
// #define FILEOI
#define lc (i<<1)
#define rc (i<<1|1)
#define rep(i,__l,__r) for(int i=__l,i##_end_=__r;i<=i##_end_;++i)
#define dep(i,__l,__r) for(int i=__l,i##_end_=__r;i>=i##_end_;--i)
#define cg (c=getchar())
template<class T>inline void qread(T& x){
    x=0;char c;bool f=0;
    while(cg<'0'||'9'<c)if(c=='-')f=1;
    for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
    if(f)x=-x;
}
template<class T,class... Args>inline void qread(T& x,Args&... args){qread(x),qread(args...);}
inline int qread(){
    int x=0;char c;bool f=1;
    while(cg<'0'||'9'<c)if(c=='-')f=0;
    for(x=(c^48);'0'<=cg&&c<='9';x=(x<<1)+(x<<3)+(c^48));
    return f?x:-x;
}
#undef cg
template<class T>inline T Max(const T x,const T y){return x>y?x:y;}
template<class T>inline T Min(const T x,const T y){return x<y?x:y;}
template<class T>inline T fab(const T x){return x>0?x:-x;}
template<class T>void fwrit(T x){
    if(x<0)return (void)(putchar('-'),fwrit(-x));
    if(x>10)fwrit(x/10);
    return (void)(putchar(x%10^48));
}

const int MAXN=1e5;
const int MAXM=1e5;

struct change{int op,l,r;}p[MAXM+5];
struct node{
    int l,r,mid,t1,lazy;
    node(){lazy=-1;}
    node(const int L,const int R,const int M):l(L),r(R),mid(M){lazy=-1;}
}tre[(MAXN<<2)+5];
int n,m,a[MAXN+5],t[MAXN+5],q;

inline void init(){
    qread(n,m);
    rep(i,1,n)qread(a[i]);
    for(int i=1;i<=m;++i)p[i]=change{qread(),qread(),qread()};
    qread(q);
}

inline void pushup(const int i){tre[i].t1=tre[lc].t1+tre[rc].t1;}

inline void pushdown(const int i){
    if(tre[i].l^tre[i].r){
        if(tre[i].lazy==1){
            tre[lc].lazy=tre[rc].lazy=1;
            tre[lc].t1=(tre[lc].r-tre[lc].l+1);
            tre[rc].t1=(tre[rc].r-tre[rc].l+1);
        }
        else if(tre[i].lazy==0){
            tre[lc].lazy=tre[rc].lazy=0;
            tre[lc].t1=tre[rc].t1=0;
        }
    }
    tre[i].lazy=-1;
}

inline void buildtre(const int i,const int l,const int r,const int x){
    // printf("buildtre : %d %d %d %d\n",i,l,r,x);
    int mid=(l+r)>>1;
    tre[i]=node(l,r,mid);
    if(l==r)return (void)(tre[i].t1=(a[l]>=x));
    buildtre(lc,l,mid,x);
    buildtre(rc,mid+1,r,x);
    pushup(i);
}

inline int query(const int i,const int l,const int r){
    // printf("query : %d %d %d\n",i,l,r);
    if(l<=tre[i].l&&tre[i].r<=r)return tre[i].t1;
    if(tre[i].lazy!=-1)pushdown(i);
    int ret=0;
    if(l<=tre[i].mid)ret+=query(lc,l,r);
    if(tre[i].mid<r)ret+=query(rc,l,r);
    pushup(i);
    return ret;
}

inline void update(const int i,const int l,const int r,const int var){
    // if(l>r)return;
    // printf("update : %d to %d, %d\n",l,r,var);
    if(l<=tre[i].l&&tre[i].r<=r){
        tre[i].lazy=var;
        tre[i].t1=(tre[i].r-tre[i].l+1)*var;
        return;
    }
    if(tre[i].lazy!=-1)pushdown(i);
    if(l<=tre[i].mid)update(lc,l,r,var);
    if(tre[i].mid<r)update(rc,l,r,var);
    pushup(i);
}

inline int query(const int i,const int p){
    // printf("update : %d %d\n",i,p);
    if(tre[i].l==tre[i].r)return tre[i].t1;
    if(tre[i].lazy!=-1)pushdown(i);
    int ret;
    if(p<=tre[i].mid)ret=query(lc,p);
    else ret=query(rc,p);
    pushup(i);
    return ret;
}

inline bool check(const int x){
    // printf("Now check : x == %d\n",x);
    buildtre(1,1,n,x);
    // for(int i=1;i<=13;++i)printf("tre[%d] : %d %d %d %d %d\n",i,tre[i].l,tre[i].r,tre[i].mid,tre[i].t1,tre[i].lazy);
    rep(i,1,m){
        int cnt1=query(1,p[i].l,p[i].r);
        int cnt0=p[i].r-p[i].l+1-cnt1;
        // printf("query : %d %d, cnt1 == %d, cnt0 == %d\n",p[i].l,p[i].r,cnt1,cnt0);
        if(p[i].op==0){
            if(cnt0)update(1,p[i].l,p[i].l+cnt0-1,0);
            if(cnt1)update(1,p[i].l+cnt0,p[i].r,1);
            // printf("update : %d to %d, %d\n",p[i].l,p[i].l+cnt0-1,0);
            // printf("update : %d to %d, %d\n",p[i].l+cnt0,p[i].r,1);
        }
        else{
            if(cnt1)update(1,p[i].l,p[i].l+cnt1-1,1);
            if(cnt0)update(1,p[i].l+cnt1,p[i].r,0);
            // printf("update : %d to %d, %d\n",p[i].l,p[i].l+cnt1-1,0);
            // printf("update : %d to %d, %d\n",p[i].l+cnt1,p[i].r,1);
        }
        // printf("Now The info of the tre :\n");
        // for(int j=1;j<=13;++j)printf("tre[%d] : %d %d %d %d %d\n",j,tre[j].l,tre[j].r,tre[j].mid,tre[j].t1,tre[j].lazy);
    }
    // printf("When x == %d,ans == %d\n",x,query(1,q));
    return query(1,q);
}

inline void biSearch(){
    int l=0,r=n,x=0,ans;
    while(l<=r){
        x=(l+r)>>1;
        if(check(x))ans=x,l=x+1;
        else r=x-1;
    }
    fwrit(ans),putchar('\n');
}

signed main(){
#ifdef FILEOI
    freopen("sort.in","r",stdin);
    freopen("sort.out","w",stdout);
#endif
    init();
    biSearch();
    return 0;
}

T3 "THUWC 2017" random bipartite graph

topic

click here

Examination room ideas

See bipartite graph to see mathematical expectation, skip While the problem may not have been behind the jump

Correct

Talk for a long time, a little faint, let me slow it ...

Guess you like

Origin www.cnblogs.com/Arextre/p/12210548.html