JNday3-am

预计分数 ? + 0 + 50;

实际分数 A + 0 + 50;

这套题感觉还行

T1感觉没啥思路,首先放弃,先做T3

T3的思路之前见过,然后没多长时间就写了出来,然后自己调试了很长时间过了样例,
之后由于一些不可描述的原因,GG了,(这个原因我也不想再说了。。。。。。)
然后写了个暴力 + 一个线段树的区间查询最大值的板子题;

T1看了看样例,每组数据只要有偶数,那么就可以,虽然不能严谨的证明,但是骗过了

现在,已经没多长时间了。。。。。。(貌似还有不到15min)

T2表面一看,题面和昨天的T2一样,貌似是一个30min可以写出的爆搜,然而时间不够,就放弃了,
然后看到很多40分的人,就读了一下题面,原来一个简单的 N^2 就可以过,GG,竟然没看,丢了40分

总结:T2凭经验放弃,这是很不理智的,(起码得看一下吧)
T1骗分比较成功(其实yy出来的就是正解嘛)
T3 板子的东西一定要敲的非常熟练,如果T3敲的快,那就还有不少时间来“看”T2吧。

 T1 星空

#include<cstdio>
#include<cstdlib>
#include<cstring>

using namespace std;

int n,m;

int main()
{
    freopen("star.in","r",stdin);
    freopen("star.out","w",stdout);

    while (~scanf("%d%d",&n,&m))
    {
        if (!n && !m) break;
        if ((n&1)&&(m&1)) printf("Chito\n");
        else printf("Yuri\n");
    }

    return 0;
}

T2 战争

#define PROC "shana"
#include <cstdio>
#include <cctype>
#include <memory.h>
#include <algorithm>
#include<cctype>

using namespace std;

typedef long long qw;

#define _l (qw)
const int BUF_SIZE = 30;
char buf[BUF_SIZE], *buf_s = buf, *buf_t = buf + 1;
  
#define PTR_NEXT() \
    { \
        buf_s ++; \
        if (buf_s == buf_t) \
        { \
            buf_s = buf; \
            buf_t = buf + fread(buf, 1, BUF_SIZE, stdin); \
        } \
    }
   
#define readInt(_n_) \
    { \
        while (*buf_s != '-' && !isdigit(*buf_s)) \
            PTR_NEXT(); \
        bool register _nega_ = false; \
        if (*buf_s == '-') \
        { \
            _nega_ = true; \
            PTR_NEXT(); \
        } \
        int register _x_ = 0; \
        while (isdigit(*buf_s)) \
        { \
            _x_ = _x_ * 10 + *buf_s - '0'; \
            PTR_NEXT(); \
        } \
        if (_nega_) \
            _x_ = -_x_; \
        (_n_) = (_x_); \
    }

const int maxn = 50010;
const int maxl = 31;
const int maxnd = maxn * maxl;
const int mod = 1e9 + 7;
const int inv = 500000004;

int v0, n, rt, tn, a[maxn];
int tr[maxnd][2], rb[maxnd][maxl], c[maxnd];
qw k;

void trieIns(int v) {
    int p = rt;
    for (int i = maxl - 1; i >= 0; -- i) {
        int v0 = (v >> i) & 1;
        if (!tr[p][v0])
            tr[p][v0] = ++ tn;
        p = tr[p][v0];
        ++ c[p];
        for (int j = maxl - 1; j >= 0; -- j)
            if ((v >> j) & 1)
                ++ rb[p][j];
    }
}

int cntUpper(int v, int vu) {
    int p = rt, s = 0;
    for (int i = maxl - 1; i >= 0; -- i) {
        int v0 = (v >> i) & 1;
        if ((vu >> i) & 1) {
            p = tr[p][v0 ^ 1];
        }
        else {
            s += c[tr[p][v0 ^ 1]];
            p = tr[p][v0];
        }
    }
    return s;
}

qw check(int v) {
    qw s = 0;
    for (int i = 0; i < n; ++ i)
        s += cntUpper(a[i], v);
    return s >> 1;
}

int sumUpper(int v, int vu) {
    int s = 0, p = rt;
    for (int i = maxl - 1; i >= 0; -- i) {
        int v0 = (v >> i) & 1;
        if ((vu >> i) & 1)
            p = tr[p][v0 ^ 1];
        else {
            for (int j = 0; j < maxl; ++ j)
                if ((v >> j) & 1)
                    s = (_l s + (1LL << j) * (_l c[tr[p][v0 ^ 1]] - _l rb[tr[p][v0 ^ 1]][j])) % mod;
                else
                    s = (_l s + (1LL << j) * _l rb[tr[p][v0 ^ 1]][j]) % mod;
            p = tr[p][v0];
        }
    }
    return s;
}

int main() {
    freopen("war.in", "r", stdin);
    freopen("war.out", "w", stdout);

    readInt(n);
    readInt(k);
    rt = 1;
    tn = 1;
    for (int i = 0; i < n; ++ i) {
        readInt(a[i]);
        trieIns(a[i]);
    }
    {
        int l = 0, r = 2147483647;
        while (l < r) {
            int mid = (_l l + r + 1) >> 1;
            if (check(mid - 1) < k)
                r = mid - 1;
            else
                l = mid;
        }
        v0 = l;
    }
    if (v0) {
        //printf("%d %lld\n", v0, check(v0));
        int ans = 0;
        for (int i = 0; i < n; ++ i)
            ans = (_l ans + sumUpper(a[i], v0 - 1)) % mod;
        ans = (_l ans * inv % mod + ((k - check(v0 - 1)) % mod + mod) * _l v0) % mod;
        printf("%d\n", ans);
    }
    else {
        int ans = 0;
        for (int i = 0; i < n; ++ i)
            ans = (_l ans + sumUpper(a[i], 0)) % mod;
        ans = _l ans * inv % mod;
        printf("%d\n", ans);
    }
}

T3 无题

#include<cstdio>
#include<cstdlib>
#include<cstring>

using namespace std;

#define wmt 1,n,1
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

const int maxn=100010;
const int maxk=10;

int n,m,col[maxn<<2|1];

struct rec
{
    int res[maxk];
    rec(){memset(res,0,sizeof(res));}
    rec operator+(const rec &b)const {
        rec z;
        int p1=0,p2=0;
        for (int a=0;a<maxk;a++)
            if (res[p1]>b.res[p2]) z.res[a]=res[p1++];
            else z.res[a]=b.res[p2++];
        return z;
    }
}z[maxn<<2|1];

void color(int rt,int c)
{
    col[rt]+=c;
    for (int a=0;a<maxk;a++)
        if (z[rt].res[a]) z[rt].res[a]+=c;
}

void push_col(int rt) {
    if (col[rt]) {
        color(rt<<1,col[rt]);
        color(rt<<1|1,col[rt]);
        col[rt]=0;
    }
}

void update(int rt) {
    z[rt]=z[rt<<1]+z[rt<<1|1];
}

void build(int l,int r,int rt)
{
    if (l==r) {
        scanf("%d",&z[rt].res[0]);
        return;
    }
    int m=(l+r)>>1;
    build(lson);
    build(rson);
    update(rt);
}

rec query(int l,int r,int rt,int nowl,int nowr)
{
    if (nowl<=l && r<=nowr) return z[rt];
    push_col(rt);
    int m=(l+r)>>1;
    if (nowl<=m)
    {
        if (m<nowr) return query(lson,nowl,nowr)+query(rson,nowl,nowr);
        else return query(lson,nowl,nowr);
    }
    else return query(rson,nowl,nowr);
}

void modify(int l,int r,int rt,int nowl,int nowr,int v)
{
    if (nowl<=l && r<=nowr)
    {
        color(rt,v);
        return;
    }
    push_col(rt);
    int m=(l+r)>>1;
    if (nowl<=m) modify(lson,nowl,nowr,v);
    if (m<nowr) modify(rson,nowl,nowr,v);
    update(rt);
}

int main()
{
    freopen("noname.in","r",stdin);
    freopen("noname.out","w",stdout);

    scanf("%d%d",&n,&m);
    build(wmt);
    for (int a=1;a<=m;a++)
    {
        int opt,l,r,v;
        scanf("%d%d%d%d",&opt,&l,&r,&v);
        if (opt==0) 
        {
            if (r-l+1<v) printf("-1\n");
            else printf("%d\n",query(wmt,l,r).res[v-1]);
        }
        else modify(wmt,l,r,v);
    }

    return 0;
}

 

posted @ 2017-10-30 21:19  ioioioioioio  阅读(146)  评论(0编辑  收藏  举报