EZ 2018 05 13 NOIP2018 模拟赛(十三)
这次的比赛真心水,考时估分240,然后各种悠闲乱逛
然后测完T1数组开小了炸成40,T2,T3都没开long long,T2炸成20,T3爆0
掉回1600+的深渊,但是还有CJJ dalao比我更惨,链接
T1
这道题就比较simple了,很显然用数据结构乱优化
貌似有很多种解法:单调队列,堆,线段树等等
我主要就讲一下我考试的时候YY出来的线段树
首先我们发现一个性质:对于n次操作之后,序列就进入循环
然后我们只需要处理处前n次询问就可以O(n)处理了
我们开一个前缀和记录原串中1的个数,然后设一个数组f[i]表示i左边k的长度范围内(包括它自己)一共有几个1(不足k也允许)
然后我们发现将一个数从尾部移到最前面,有两种情况:
如果这个数是0,那么只需要把它自己的f[i]修改成0即可
如果这个数是1,那么只需要把它自己的f[i]就改成1,并且把队头的前k-1项的f[]值加1
然后我们之间把初始数组右移n个长度(前面的为循环做准备),然后上线段树即可
然而我f数组忘记<<1了,而且那个字符串数组也看错了范围dog!!!
CODE
#include<cstdio>
#include<cstring>
using namespace std;
const int N=100005;
struct segtree
{
int add,s;
}tree[N<<3];
int a[N],f[N<<1],sum[N],ans[N],n,k,q,tot;
char s[N<<1];
inline void read(int &x)
{
x=0; char ch=getchar();
while (ch<'0'||ch>'9') ch=getchar();
while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
}
inline void write(int x)
{
if (x/10) write(x/10);
putchar(x%10+'0');
}
inline int max(int a,int b)
{
return a>b?a:b;
}
inline void up(int root)
{
tree[root].s=max(tree[root<<1].s,tree[root<<1|1].s);
}
inline void down(int root)
{
if (tree[root].add)
{
tree[root<<1].add+=tree[root].add;
tree[root<<1|1].add+=tree[root].add;
tree[root<<1].s+=tree[root].add;
tree[root<<1|1].s+=tree[root].add;
tree[root].add=0;
}
}
inline void build(int root,int l,int r)
{
if (l==r)
{
tree[root].s=f[l];
return;
}
int mid=l+r>>1;
build(root<<1,l,mid); build(root<<1|1,mid+1,r);
up(root);
}
inline void updata(int root,int l,int r,int id)
{
if (l==r)
{
tree[root].s=0;
return;
}
int mid=l+r>>1;
down(root);
if (id<=mid) updata(root<<1,l,mid,id); else updata(root<<1|1,mid+1,r,id);
up(root);
}
inline void modify(int root,int l,int r,int beg,int end)
{
if (l>=beg&&r<=end)
{
tree[root].s+=1; tree[root].add+=1;
return;
}
int mid=l+r>>1;
down(root);
if (beg<=mid) modify(root<<1,l,mid,beg,end);
if (end>mid) modify(root<<1|1,mid+1,r,beg,end);
up(root);
}
int main()
{
//freopen("A.in","r",stdin); freopen("A.out","w",stdout);
register int i;
read(n); read(k); read(q);
for (i=1;i<=n;++i)
{
read(a[i]); sum[i]=sum[i-1]+a[i];
if (i>=k) f[i+n]=sum[i]-sum[i-k]; else f[i+n]=sum[i];
}
build(1,1,n<<1);
ans[0]=tree[1].s;
for (i=1;i<=n;++i)
{
updata(1,1,n<<1,(n<<1)-i+1);
if (a[n-i+1]) modify(1,1,n<<1,n-i+1,n-i+k);
ans[i]=tree[1].s;
}
for (scanf("%s",s+1),i=1;i<=q;++i)
if (s[i]=='?') write(ans[tot]),putchar('\n'); else { if (++tot==n) tot=0; }
return 0;
}
T2
这题意一看就是暴力数据结构,然而我没开long long
我们通过观察发现2操作满足一个很凶猛的性质:前面的操作不会影响后面的操作
因此我们可以从前往后推一下,对于所有的操作2,将它操作的区间中的所有操作的次数+=目前这个操作的次数(默认为1)
然后最后我们得到了所有操作的次数,然后对于操作1上线段树 or 树状数组+差分即可
线段树CODE
#include<cstdio>
using namespace std;
typedef long long LL;
const LL N=100005,mod=1e9+7;
struct time_segtree
{
LL add[N<<2],sum[N<<2];
inline void up(LL root)
{
sum[root]=(sum[root<<1]+sum[root<<1|1])%mod;
}
inline void down(LL root,LL l,LL r)
{
if (add[root])
{
add[root<<1]=(add[root<<1]+add[root])%mod;
add[root<<1|1]=(add[root<<1|1]+add[root])%mod;
sum[root<<1]=(sum[root<<1]+add[root]*l)%mod;
sum[root<<1|1]=(sum[root<<1|1]+add[root]*r)%mod;
add[root]=0;
}
}
inline void modify(LL root,LL l,LL r,LL beg,LL end,LL k)
{
if (l>=beg&&r<=end)
{
sum[root]=(sum[root]+k*(r-l+1))%mod;
add[root]=(add[root]+k)%mod;
return;
}
LL mid=l+r>>1;
down(root,mid-l+1,r-mid);
if (beg<=mid) modify(root<<1,l,mid,beg,end,k);
if (end>mid) modify(root<<1|1,mid+1,r,beg,end,k);
up(root);
}
inline LL query(LL root,LL l,LL r,LL id)
{
if (l==r) return sum[root];
LL mid=l+r>>1;
down(root,mid-l+1,r-mid);
if (id<=mid) return query(root<<1,l,mid,id); else return query(root<<1|1,mid+1,r,id);
}
}T;
struct ans_segtree
{
LL add[N<<2],sum[N<<2];
inline void up(LL root)
{
sum[root]=(sum[root<<1]+sum[root<<1|1])%mod;
}
inline void down(LL root,LL l,LL r)
{
if (add[root])
{
add[root<<1]=(add[root<<1]+add[root])%mod;
add[root<<1|1]=(add[root<<1|1]+add[root])%mod;
sum[root<<1]=(sum[root<<1]+add[root]*l)%mod;
sum[root<<1|1]=(sum[root<<1|1]+add[root]*r)%mod;
add[root]=0;
}
}
inline void modify(LL root,LL l,LL r,LL beg,LL end,LL k)
{
if (l>=beg&&r<=end)
{
sum[root]=(sum[root]+k*(r-l+1))%mod;
add[root]=(add[root]+k)%mod;
return;
}
LL mid=l+r>>1;
down(root,mid-l+1,r-mid);
if (beg<=mid) modify(root<<1,l,mid,beg,end,k);
if (end>mid) modify(root<<1|1,mid+1,r,beg,end,k);
up(root);
}
inline LL query(LL root,LL l,LL r,LL id)
{
if (l==r) return sum[root];
LL mid=l+r>>1;
down(root,mid-l+1,r-mid);
if (id<=mid) return query(root<<1,l,mid,id); else return query(root<<1|1,mid+1,r,id);
}
}A;
struct data
{
LL opt,x,y;
}q[N];
LL n,m;
inline char tc(void)
{
static char fl[100000],*A=fl,*B=fl;
return A==B&&(B=(A=fl)+fread(fl,1,100000,stdin),A==B)?EOF:*A++;
}
inline void read(LL &x)
{
x=0; char ch=tc();
while (ch<'0'||ch>'9') ch=tc();
while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=tc();
}
inline void write(LL x)
{
if (x/10) write(x/10);
putchar(x%10+'0');
}
int main()
{
//freopen("B.in","r",stdin); freopen("B.out","w",stdout);
register LL i;
read(n); read(m);
for (i=1;i<=m;++i)
read(q[i].opt),read(q[i].x),read(q[i].y);
for (i=m;i>=1;--i)
{
T.modify(1,1,m,i,i,1);
if (q[i].opt==2) { LL x=T.query(1,1,m,i); T.modify(1,1,m,q[i].x,q[i].y,x); }
}
for (i=1;i<=m;++i)
if (q[i].opt==1) { LL x=T.query(1,1,m,i); A.modify(1,1,n,q[i].x,q[i].y,x); }
for (i=1;i<=n;++i)
write(A.query(1,1,n,i)),putchar(' ');
return 0;
}
T3
比较玄学的卢卡斯定理乱推
反正我对这种数学的东西没什么兴趣,还是打打暴力好了
这里的暴力也比较有技巧,我们搞一下每一个点第x天的权值,记录下来,因为既可以用来推后面的,也可以用来O(1)求答案
40ptsCODE
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
const LL N=1005;
struct edge
{
LL to,next;
}e[N<<1];
LL head[N],w[N][N],a[N],n,q,x,y,root,cnt,m;
inline char tc(void)
{
static char fl[100000],*A=fl,*B=fl;
return A==B&&(B=(A=fl)+fread(fl,1,100000,stdin),A==B)?EOF:*A++;
}
inline void read(LL &x)
{
x=0; char ch=tc();
while (ch<'0'||ch>'9') ch=tc();
while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=tc();
}
inline void write(LL x)
{
if (x/10) write(x/10);
putchar(x%10+'0');
}
inline void add(LL x,LL y)
{
e[++cnt].to=y; e[cnt].next=head[x]; head[x]=cnt;
}
inline LL max(LL a,LL b)
{
return a>b?a:b;
}
inline void DFS(LL now,LL fa)
{
bool flag=1; register LL i,j;
for (i=head[now];i!=-1;i=e[i].next)
if (e[i].to!=fa)
{
flag=0;
DFS(e[i].to,now);
}
if (flag) for (i=1;i<=m;++i) w[now][i]=w[now][0]; else
{
for (i=1;i<=m;++i)
for (w[now][i]=w[now][i-1],j=head[now];j!=-1;j=e[j].next)
if (e[j].to!=fa) w[now][i]^=w[e[j].to][i];
}
}
int main()
{
//freopen("C.in","r",stdin); freopen("C.out","w",stdout);
register LL i;
memset(head,-1,sizeof(head));
memset(e,-1,sizeof(e));
read(n); read(q);
for (i=1;i<n;++i)
read(x),read(y),add(x,y),add(y,x);
for (i=0;i<n;++i)
read(w[i][0]);
for (i=1;i<=q;++i)
read(a[i]),m=max(m,a[i]);
DFS(root,-1);
for (i=1;i<=q;++i)
write(w[root][a[i]]),putchar('\n');
return 0;
}
EZ 2018 05 13 NOIP2018 模拟赛(十三)的更多相关文章
- EZ 2018 05 26 NOIP2018 模拟赛(十六)
这次难道就是传说中的标准分大赛?而且这次比赛的链接不翼而飞了 一堆人153pts然后就有Rank4?看来这个Rank4不值钱了,才涨了50+的Rating. 不过还好最后5min的时候想出了T1正解, ...
- EZ 2018 05 20 NOIP2018 模拟赛(十五)
这次的比赛充满着玄学的气息,玄学链接 首先讲一下为什么没有第十四场 其实今天早上9点时看到题目就叫了:原题! 没错,整套试卷都做过,我还写了题解 然后老叶就说换一套,但如果仅仅是这样就没什么 但等13 ...
- EZ 2018 05 04 NOIP2018 模拟赛(十二)
这次的试卷应该是激励我们一下的,链接 然后大家的分数就都很高,然后我就210被一群秒A T2的240大佬爆踩 掉了5rating但Rank竟然发杀了 X_o_r dalao && YZ ...
- EZ 2018 05 01 NOIP2018 模拟赛(十一)
莫名其妙暴涨Rating 其实题目都挺好挺简单的,但是越简单就越容易ZZ 不理解问什么第一题这么多人找环 不过T2是真心细节题,T3太难了 题目戳这里 T1 仔细分析题意发现那个交换规则就是废话,如果 ...
- EZ 2018 04 13 NOIP2018 模拟赛(八)
这次的题目都是什么鬼? 玄学乱搞+肉眼看CODE+倒着搜索? 好吧是我ZZ了 链接在此 T1 玄学乱搞 由于考场上写的部分分做法忘记讨论n<=2000时的情况,少得了30pts 很容易得到一个基 ...
- EZ 2018 06 17 NOIP2018 模拟赛(十九)
这次的题目难得的水,但是由于许多哲学的原因,第二题题意表述很迷. 然后是真的猜题意了搞了. 不过这样都可以涨Rating我也是服了. Upt:链接莫名又消失了 A. 「NOIP2017模拟赛11.03 ...
- EZ 2018 06 10 NOIP2018 模拟赛(十八)
好久没写blog&&比赛题解了,最近补一下 这次还是很狗的,T3想了很久最后竟然连并查集都忘写了,然后T2map莫名爆炸. Rating爆减......链接不解释 好了我们开始看题. ...
- EZ 2018 06 24 NOIP2018 模拟赛(二十)
很久之前写的一套题了,由于今天的时间太多了,所以记起来就写掉算了. 这一场尽管T2写炸了,但也莫名Rank4涨了Rating.不过还是自己太菜. A. 环游世界 首先我们先排个序,想一下如果不用走回来 ...
- EZ 2018 06 02 NOIP2018 模拟赛(十七)
这次的比赛是真心比较狗,我TM的写了30min的树剖ZZ地直接memset超时了 话说我既然想到差分就应该去写差分的啊! 好了不过这次Rank还挺高的,终于要打进前10了当然是假的了. 好了下面开始讲 ...
随机推荐
- VS2010部署相关
找到一篇写得最负责的.贴住收藏了: http://blog.csdn.net/xhf55555/article/details/7702212. 之前在其它地方找的都缺胳膊少腿,真不知他们自己怎么实现 ...
- android中checkbox自定义样式
1.首先res/drawable中定义checkbox_style.xml样式: <?xml version="1.0" encoding="utf-8" ...
- 关于win10下JDK环境变量的配置以及关于JDK的一些说明
一.JDK的下载和安装 这里提供32位和64位JDK的下载链接 百度网盘:https://pan.baidu.com/s/1xtiVOE2gPCvlGCTy0vfBaw 密码:c5m4 官网:ht ...
- LintCode题解之Search Range in Binary Search Tree
1.题目描述 2.问题分析 首先将二叉查找树使用中序遍历的方式将元素放入一个vector,然后在vector 中截取符合条件的数字. 3.代码 /** * Definition of TreeNode ...
- HBase的写事务,MVCC及新的写线程模型
MVCC是实现高性能数据库的关键技术,主要为了读不影响写.几乎所有数据库系统都用这技术,比如Spanner,看这里.Percolator,看这里.当然还有mysql.本文说HBase的MVCC和0.9 ...
- Oracle EBS OM 登记订单
DECLARE l_header_rec OE_ORDER_PUB.Header_Rec_Type; l_line_tbl OE_ORDER_PUB.Line_Tbl_Type; l_action_r ...
- .net 操作MongoDB 基础
1. 下载驱动,最好使用 NuGet 下载,直接搜索MongoDB: 2. 引用相关驱动 3. 部分测试代码,主要是针对MongoDB的GridFS 文件存储来用 using Mongo.Model; ...
- /etc/sudoers文件的分析以及sudo的高级用法
高级用法总结: sudo命令是普通用户的提权操作指令.在权限控制中,我们可以使用/etc/sudoers文件中来进行设置.基本的用法比较熟悉.比如设置一个普通用户可拥有root用户的运行权限,那么设置 ...
- 使用Index()+Match()函数实现更为灵活的VLookUp()
上一篇 http://www.cnblogs.com/-SANG/p/8407017.html 文章中已经介绍了vlookup的用法. 今天要使用index+match实现更为灵活的vlookup 先 ...
- 【adb命令】在cmd窗口中使用adb install命令安装 中文名字apk报错的解决办法
1.在cmd窗口中使用adb install命令安装中文名字apk报错,安装英文名字apk就正常,详细报错如下图: 2.查看adb版本号:adb version 3.怀疑是adb版本的原因,尝试换个最 ...