zoukankan      html  css  js  c++  java
  • NOI2016

    luoguP1712 [NOI2016]区间

    这是一道送分题.

    对于我这种每天抄题解不动脑子思维僵化得厉害的智障选手就是送命题.

    一直在想端点排序各种Treap搞...

    正解:

    已知一些区间,如何判断是否满足条件?满足条件是有一个点被覆盖的次数大于m,那么用线段树可以解决这个问题.
    把区间按长度排序,从小往大考虑答案中选中最长区间的最大值.加入一个新的区间,线段树上区间加,当最大值仍大于m时,按加入时间删去最早的区间即可.

     1 //Achen
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<vector>
     7 #include<cstdio>
     8 #include<queue>
     9 #include<cmath>
    10 #include<set>
    11 #include<map>
    12 #define inf 0x7fffffff
    13 #define For(i,a,b) for(int i=(a);i<=(b);i++)
    14 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
    15 const int N=1000007;
    16 typedef long long LL; 
    17 typedef double db;
    18 using namespace std;
    19 int n,m,ls[N],sz,ans;
    20 
    21 template<typename T> void read(T &x) {
    22     char ch=getchar(); x=0; T f=1;
    23     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    24     if(ch=='-') f=-1,ch=getchar();
    25     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
    26 }
    27 
    28 struct node {
    29     int l,r,ll,rr;
    30     friend bool operator <(const node&A,const node&B) {
    31         return A.r-A.l<B.r-B.l;
    32     }
    33 }p[N];
    34 
    35 #define lc x<<1
    36 #define rc ((x<<1)|1)
    37 #define mid ((l+r)>>1)
    38 int sg[N<<2],lz[N<<2];
    39 void down(int x,int l_len,int r_len) {
    40     if(!lz[x]) return;
    41     if(l_len) sg[lc]+=lz[x],lz[lc]+=lz[x];
    42     if(r_len) sg[rc]+=lz[x],lz[rc]+=lz[x];
    43     lz[x]=0;
    44 }
    45 
    46 void update(int x,int l,int r,int ql,int qr,int v) {
    47     if(l>=ql&&r<=qr) {
    48         sg[x]+=v; lz[x]+=v; return;
    49     }
    50     down(x,mid-l+1,r-mid);
    51     if(ql<=mid) update(lc,l,mid,ql,qr,v);
    52     if(qr>mid) update(rc,mid+1,r,ql,qr,v);
    53     sg[x]=max(sg[lc],sg[rc]);    
    54 }
    55 
    56 //#define DEBUG
    57 int main() {
    58 #ifdef DEBUG
    59     freopen("1.in","r",stdin);
    60     //freopen(".out","w",stdout);
    61 #endif
    62     read(n); read(m);
    63     For(i,1,n) {
    64         read(p[i].l); read(p[i].r);
    65         ls[++ls[0]]=p[i].l; ls[++ls[0]]=p[i].r;
    66     }
    67     sort(ls+1,ls+ls[0]+1);
    68     sz=unique(ls+1,ls+ls[0]+1)-(ls+1);
    69     sort(p+1,p+n+1);
    70     ans=inf; int pos=1;
    71     For(i,1,n) {
    72         p[i].ll=lower_bound(ls+1,ls+sz+1,p[i].l)-ls;
    73         p[i].rr=lower_bound(ls+1,ls+sz+1,p[i].r)-ls;
    74         update(1,1,sz,p[i].ll,p[i].rr,1);
    75         while(sg[1]>=m) {
    76             ans=min(ans,(p[i].r-p[i].l)-(p[pos].r-p[pos].l));
    77             update(1,1,sz,p[pos].ll,p[pos].rr,-1); pos++;
    78         }
    79     }
    80     if(ans==inf) ans=-1;
    81     printf("%d
    ",ans);
    82     return 0;
    83 }
    View Code

    luoguP1173 [NOI2016]网格

    对于细节苦手考虑问题永远没法全面连Noipdtt2傻逼模拟题都写挂的智障选手又是一道送命题.

    一开始以为大力特判一波就可以,发现很多情况没考虑到.

    要离散求割点.

    答案显然只有 -1,0,1,2

    若跳蚤个数小于等于2且联通则为-1

    图不联通则为0

    否则有割点则为1

    否则为2

    关键就是离散求割点.

    我是把每个蛐蛐周围一圈24个跳蚤拿下来,再把他们对应的上下左右贴着边界的跳蚤拿出来建图,然后跑tarjan

    没有看懂只用24个跳蚤和只用8个跳蚤再往外一圈的题解

    我直接跑tarjan的话,如果只拿8个跳蚤或者不拿最外面一圈,可以卡掉的数据:

    4 1 1

    1 1

    还有注意特判n,m乘积的时候要开LL.......

     1 //Achen
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<vector>
     7 #include<cstdio>
     8 #include<queue>
     9 #include<cmath>
    10 #include<set>
    11 #include<map>
    12 #define inf 0x7fffffff
    13 #define For(i,a,b) for(int i=(a);i<=(b);i++)
    14 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
    15 const int N=1000007;
    16 typedef long long LL; 
    17 typedef double db;
    18 using namespace std;
    19 int n,m,ls[N],sz,ans;
    20 
    21 template<typename T> void read(T &x) {
    22     char ch=getchar(); x=0; T f=1;
    23     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    24     if(ch=='-') f=-1,ch=getchar();
    25     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
    26 }
    27 
    28 struct node {
    29     int l,r,ll,rr;
    30     friend bool operator <(const node&A,const node&B) {
    31         return A.r-A.l<B.r-B.l;
    32     }
    33 }p[N];
    34 
    35 #define lc x<<1
    36 #define rc ((x<<1)|1)
    37 #define mid ((l+r)>>1)
    38 int sg[N<<2],lz[N<<2];
    39 void down(int x,int l_len,int r_len) {
    40     if(!lz[x]) return;
    41     if(l_len) sg[lc]+=lz[x],lz[lc]+=lz[x];
    42     if(r_len) sg[rc]+=lz[x],lz[rc]+=lz[x];
    43     lz[x]=0;
    44 }
    45 
    46 void update(int x,int l,int r,int ql,int qr,int v) {
    47     if(l>=ql&&r<=qr) {
    48         sg[x]+=v; lz[x]+=v; return;
    49     }
    50     down(x,mid-l+1,r-mid);
    51     if(ql<=mid) update(lc,l,mid,ql,qr,v);
    52     if(qr>mid) update(rc,mid+1,r,ql,qr,v);
    53     sg[x]=max(sg[lc],sg[rc]);    
    54 }
    55 
    56 //#define DEBUG
    57 int main() {
    58 #ifdef DEBUG
    59     freopen("1.in","r",stdin);
    60     //freopen(".out","w",stdout);
    61 #endif
    62     read(n); read(m);
    63     For(i,1,n) {
    64         read(p[i].l); read(p[i].r);
    65         ls[++ls[0]]=p[i].l; ls[++ls[0]]=p[i].r;
    66     }
    67     sort(ls+1,ls+ls[0]+1);
    68     sz=unique(ls+1,ls+ls[0]+1)-(ls+1);
    69     sort(p+1,p+n+1);
    70     ans=inf; int pos=1;
    71     For(i,1,n) {
    72         p[i].ll=lower_bound(ls+1,ls+sz+1,p[i].l)-ls;
    73         p[i].rr=lower_bound(ls+1,ls+sz+1,p[i].r)-ls;
    74         update(1,1,sz,p[i].ll,p[i].rr,1);
    75         while(sg[1]>=m) {
    76             ans=min(ans,(p[i].r-p[i].l)-(p[pos].r-p[pos].l));
    77             update(1,1,sz,p[pos].ll,p[pos].rr,-1); pos++;
    78         }
    79     }
    80     if(ans==inf) ans=-1;
    81     printf("%d
    ",ans);
    82     return 0;
    83 }
    View Code

    [NOI2016]国王饮水记

    真 送命题

    感觉70分可以连蒙带猜瞎那啥伪证一波,话说回来我也不会用高精小数库呀

    我就靠llj和sxy了

    [NOI2016]优秀的拆分

    传送门

    听说是送分题

    当时的我没做出来

    感觉现在的我不知道题解仍然做不来

    不过95分暴力倒是美滋兹

    [NOI2016]循环之美

    好心累啊,不想写题解,放个传送门

    听说这是一道模板题

    为什么你们家的模板题都这么难的呀

    我怎么做模板题做一天呀

    不知道是不是太久没做数学题了,半天连个柿子都列不出来

    等到终于知道自己要干啥子了,然后看着k^x=1(mod j)很久很久

    愣是没看出来gcd(k,j)==1

    我是猪头吗(

    然后开始推一个伪柿子

    又推了很久

    打出来调过了样例

    试了几个小数据发现柿子萎了,得做成40*nlog,试图挣扎.无果

    抄题解

    发现完全忘了有可以从和前i个质因子互质dp转移这种事情

    真是菜得抠脚

    前几天一上午or一下午or一晚上做一道题,现在是一天做一道题,我怕不是要与太阳肩并肩

    View Code
  • 相关阅读:
    go1.13 mod 实践和常见问题
    etcd 添加用户,授权特定目录
    golang 你所不知道的 log 和 fmt
    redis 原理系列之--字符串存储的实现原理(1)
    golang 写文件--详细解释
    面向对象范式的核心本质是?---不是继承 不是封装也不是多态
    关于自控力和拖延 的一点分享--《自控力》
    Linux 精确判断是否同一文件--及终端获取字符串md5 的值
    ARM版本及系列
    技术团队塑造
  • 原文地址:https://www.cnblogs.com/Achenchen/p/8987262.html
Copyright © 2011-2022 走看看