链接

下午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. CF 414B Mashmokh and ACM 动态规划

    题意: 给你两个数n和k.求满足以下条件的数列有多少个. 这个数列的长度是k: b[1], b[2], ……, b[k]. 并且 b[1] <= b[2] <= …… <= b[k] ...

  2. 题解 CF915D 【Almost Acyclic Graph】

    这道题我第一次的想法是直接判环的数量,然而事实证明实在是太naive了. 随便画个图都可以卡掉我的解法.(不知道在想什么) 这道题的正解是拓扑排序. 朴素的想法是对所有边都跑一次拓扑,但这样$O(m( ...

  3. 【转】CentOS下firefox安装flash说明

    http://www.cnblogs.com/lamper/archive/2013/01/16/2862254.htm CentOS下自带了firefox,但没有flash插件的,按它自己的提示安装 ...

  4. typedef 与 set_new_handler的几种写法

    可以用Command模式.函数对象来代替函数指针,获得以下的好处: 1. 可以封装数据 2. 可以通过虚拟成员获得函数的多态性 3. 可以处理类层次结果,将Command与Prototype模式相结合 ...

  5. error:assign attribute must be unsafeunretained

    今天在使用协议的过程中.偶然发现这样使用 ? 1 2 3 4 5 6 7 8 9 10 @interface AppDelegate (){     id<chatdelegate>  t ...

  6. Android之Handler源代码深入解析

    闲着没事.就来看看源代码,看看源代码的各种原理,会用仅仅是简单的,知道为什么才是最牛逼的. Handler源代码分析那,从使用的步骤来边用边分析: 1.创建一个Handler对象:new Handle ...

  7. python + eclipse + django + postgresql 开发网站(一)

    一.配置开发环境 1.安装Python 载地址下:http://www.python.org/getit/

  8. PatentTips - Virtual translation lookaside buffer

    BACKGROUND OF THE INVENTION A conventional virtual-machine monitor (VM monitor) typically runs on a ...

  9. Android NDK课程录制完毕上线

    近期依据公司安排,录制了Android NDK开发的内容,总体课程能够在www.iotekclass.com上看到.兴许会慢慢的用blog把这些内容展示出来. 此课程大纲例如以下: 第一章 NDK简单 ...

  10. Oracle的表空间和sqlplus

    1.  表空间的概念 曾经接触过的数据库都没有听到过表空间这个词,在前一段时间看到Oracle数据库的时候发现表空间无处不在. 所以表空间在Oracle数据库中应该是一个非经常常使用而且非常重要的概念 ...