链接

下午5点的时候,突然想起来有这个比赛,看看还有一个小时,打算来AK一下,结果因为最近智商越来越低,翻车了,我还是太菜了。上来10分钟先切掉了C和A,结果卡在了B题,唉。

A.砍树

一眼题,两遍树形DP分黑的多还是白的多

#include<bits/stdc++.h>
#define REP(i,a,b) for(int i(a);i<=(b);++i)
#define dbg(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int>pii;
inline int read(){char c,p=0;int w;
while(isspace(c=getchar()));if(c=='-')p=1,c=getchar();
for(w=c&15;isdigit(c=getchar());w=w*10+(c&15));return p?-w:w;
}
template<typename T,typename U>inline char smin(T&x,const U&y){return x>y?x=y,1:0;}
template<typename T,typename U>inline char smax(T&x,const U&y){return x<y?x=y,1:0;}
const int N=1e5+5;
int n,f[N],c[N],ans;
vector<int>g[N];
void dfs(int x,int fa){
f[x]=c[x]==1?1:-1;
for(int y:g[x])if(y!=fa){
dfs(y,x);
smax(f[x],f[x]+f[y]);
}
smax(ans,f[x]);
}
int main(){
n=read();
REP(i,1,n)c[i]=read();
REP(i,2,n){
#define pb push_back
int x=read(),y=read();
g[x].pb(y),g[y].pb(x);
}
dfs(1,0);
REP(i,1,n)c[i]^=1;
memset(f,0,sizeof f);
dfs(1,0);
cout<<ans;
return 0;
}

B.奇怪的回文串

发现满足条件需要每隔一个都相等,two pointers直接扫,线段树维护区间众数即可

考场上想了个二分答案,写了个假队列T了2个点,最近智商真是越来越低了。。

#include<bits/stdc++.h>
#define REP(i,a,b) for(int i(a);i<=(b);++i)
#define dbg(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int>pii;
inline int read(){char c,p=0;int w;
while(isspace(c=getchar()));if(c=='-')p=1,c=getchar();
for(w=c&15;isdigit(c=getchar());w=w*10+(c&15));return p?-w:w;
}
template<typename T,typename U>inline char smin(T&x,const U&y){return x>y?x=y,1:0;}
template<typename T,typename U>inline char smax(T&x,const U&y){return x<y?x=y,1:0;}
const int N=5e5+7;
int k,n,a[N];
struct hash_table{
int head[N],to[N],ne[N],T;
inline int get(int x){
int p=x%N;
for(int i=head[p];i;i=ne[i])if(to[i]==x)return i;
to[++T]=x,ne[T]=head[p],head[p]=T;return T;
}
}mp;
struct SGT{
struct node{int ls,rs,w;}t[N<<2];
int rt,cnt;
inline void clr(){rt=cnt=0;}
inline void add(int x,int v,int&o,int l=1,int r=mp.T){
if(!o)t[o=++cnt]=(node){0,0,0};
if(l==r)return (void)(t[o].w+=v);
int mid=l+r>>1;
x<=mid?add(x,v,t[o].ls,l,mid):add(x,v,t[o].rs,mid+1,r);
t[o].w=max(t[t[o].ls].w,t[t[o].rs].w);
}
inline int gmax(){return t[1].w;}
}t[2];
void solve(){
int ans=0;
t[0].clr(),t[1].clr();
int l=1;
REP(i,1,n){
t[i&1].add(a[i],1,t[i&1].rt);
while(l<=i){
int x=t[0].gmax(),y=t[1].gmax();
int c0=i/2-(l-1)/2,c1=i/2-(l-1)/2+(i&1)-(l-1&1);
if(c0-x+c1-y<=k)break;
t[l&1].add(a[l],-1,t[l&1].rt);++l;
}
smax(ans,i-l+1);
}
cout<<ans;
}
int main(){
k=read(),n=read();
REP(i,1,n)a[i]=mp.get(read());
solve();
return 0;
}

C.范围查询

经典分块题,按照模数分块,小的存下来,大的暴力

#include<bits/stdc++.h>
#define REP(i,a,b) for(int i(a);i<=(b);++i)
#define dbg(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int>pii;
inline int read(){char c,p=0;int w;
while(isspace(c=getchar()));if(c=='-')p=1,c=getchar();
for(w=c&15;isdigit(c=getchar());w=w*10+(c&15));return p?-w:w;
}
template<typename T,typename U>inline char smin(T&x,const U&y){return x>y?x=y,1:0;}
template<typename T,typename U>inline char smax(T&x,const U&y){return x<y?x=y,1:0;}
const int N=40005;
int n,q,a[N];
vector<int>g[402][402],h[N];
int main(){
n=read(),q=read();int mxx=0;
REP(i,1,n)a[i]=read(),h[a[i]].push_back(i),smax(mxx,a[i]);
int B=sqrt(mxx);
REP(i,1,B)REP(j,1,n)g[i][a[j]%i].push_back(j); while(q--){
#define Q(a) upper_bound(a.begin(),a.end(),r)-lower_bound(a.begin(),a.end(),l)
int l=read()+1,r=read()+1,x=read(),y=read();
if(x<=B)printf("%d\n",Q(g[x][y]));
else{
int ans=0;
for(int i=y;i<=mxx;i+=x)ans+=Q(h[i]);
printf("%d\n",ans);
}
}
return 0;
}

[51Nod]NOIP2018提高组省一冲奖班模测训练(四)翻车记+题解的更多相关文章

  1. [51Nod]NOIP2018提高组省一冲奖班模测训练(一)题解

    http://www.51nod.com/contest/problemList.html#!contestId=72&randomCode=147206 原题水题大赛.. A.珂朵莉的旅行 ...

  2. [51Nod]NOIP2018提高组省一冲奖班模测训练(三) 题解

    链接 A.Anan的派对 题意:Anan想举办一个派对.Anan的朋友总共有 n 人.第i个人如果参加派对会得到 \(c_i\) 的快乐值,除他自己外每多一个人参加他会减少 \(d_i\) 的快乐值. ...

  3. [51Nod]NOIP2018提高组省一冲奖班模测训练(二)

    http://www.51nod.com/contest/problemList.html#!contestId=73&randomCode=4408520896354389006 还是原题大 ...

  4. NOIP2018提高组省一冲奖班模测训练(六)

    NOIP2018提高组省一冲奖班模测训练(六) https://www.51nod.com/Contest/ContestDescription.html#!#contestId=80 20分钟AC掉 ...

  5. NOIP2018提高组省一冲奖班模测训练(五)

    NOIP2018提高组省一冲奖班模测训练(五) http://www.51nod.com/Contest/ContestDescription.html#!#contestId=79 今天有点浪…… ...

  6. NOIP2018提高组省一冲奖班模测训练(四)

    NOIP2018提高组省一冲奖班模测训练(四) 这次比赛只AC了第一题,而且花了40多分钟,貌似是A掉第一题里面最晚的 而且还有一个半小时我就放弃了…… 下次即使想不出也要坚持到最后 第二题没思路 第 ...

  7. NOIP2018提高组省一冲奖班模测训练(三)

    NOIP2018提高组省一冲奖班模测训练(三) 自己按照noip的方式考,只在最后一两分钟交了一次 第一题过了,对拍拍到尾. 第二题不会.考试时往组合计数的方向想,推公式,推了一个多小时,大脑爆炸,还 ...

  8. NOIP2018提高组省一冲奖班模测训练(二)

    比赛链接 NOIP2018提高组省一冲奖班模测训练(二) 今天发挥正常,昨天不在状态…… 花了很久A了第一题 第二题打了30分暴力 第三题投机取巧输出test1答案(连暴力都不知道怎么打,太弱了) 2 ...

  9. NOIP2018提高组省一冲奖班模测训练(一)

    比赛链接 https://www.51nod.com/contest/problemList.html#!contestId=72&randomCode=147206 这次考试的题非常有质量 ...

随机推荐

  1. javascript与DOM节点的结合使用

    文档对象模型(Document Object Model,简称DOM),是W3C组织推荐的处理可扩展标志语言的标准编程接口.在网页上,组织页面(或文档)的对象被组织在一个树形结构中,用来表示文档中对象 ...

  2. jquery中$.get()提交和$.post()提交有区别

    jquery中$.get()提交和$.post()提交有区别吗? 相同点:都是异步请求的方式来获取服务端的数据: 异同点: 1.请求方式不同:$.get() 方法使用GET方法来进行异步请求的.$.p ...

  3. spark transform系列__groupByKey

    这个操作的作用依据同样的key的全部的value存储到一个集合中的一个玩意. def groupByKey(): RDD[(K, Iterable[V])] = self.withScope {  g ...

  4. 面对即将终止支持的server你还能做些什么

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaXF1c2hp/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/d ...

  5. ubuntu12.04更新软件源时出现校验和不符

    在运行update命令之后.出现系统校验和不符.网上找了一些方法,最后在大神的帮助下最终攻克了! ! 1.更改 /etc/apt/apt.conf.d/00aptitude 文件,在最后一行增加: A ...

  6. Java并发编程 - Executor,Executors,ExecutorService, CompletionServie,Future,Callable

    一.Exectuor框架简介 Java从1.5版本开始,为简化多线程并发编程,引入全新的并发编程包:java.util.concurrent及其并发编程框架(Executor框架). Executor ...

  7. 8.不绑定(ngNonBindable)

    转自:https://www.cnblogs.com/best/tag/Angular/ ngNonBindable指令告诉Angular编译或绑定当前DOM元素的内容.这对于要求Angular忽略那 ...

  8. Spring Security Java Config Preview--官方

    原文地址:[1]https://spring.io/blog/2013/07/02/spring-security-java-config-preview-introduction/ [2]https ...

  9. Vue或React多页应用脚手架

    https://github.com/zhujiasheng/vue-multipage https://github.com/MeCKodo/vue-multipage

  10. Debian9.5 VNC Server远程桌面配置

    VNC概述 VNC (Virtual Network Console)是虚拟网络控制台的缩写.VNC 是一款优秀的远程控制工具软件,由著名的 AT&T 的欧洲研究实验室开发的.VNC 是在基于 ...