[contest 782] 9.7
[contest 782] 9.7 - XJOI
个人觉得温暖题啊,,,可是卡毛空间呀!!!
T1 传送
线性筛预处理,然后一遍BFS。显然,这个BFS是O(n)的,主要要卡的就是预处理。
code:
%:pragma gcc optimize()
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
;
int L,R,n,H,T;
],cnt;
bool isp[N];
int Q[N],f[N];
short D[N];
void Maker(){
memset(isp,,]=isp[]=;
memset(p,,,D[]=;
; i<N; i++){
;
; j<=cnt&&(long long)i*p[j]<N; j++){
isp[i*p[j]]=;
){
;
) c++,now/=p[j];
D[i*p[j]]=D[i]/(c+)*(c+);
break;
}else D[i*p[j]]=D[i]+D[i];
}
}
}
)%N,Q[T]=x;}
int main(){
Maker();
int Ts; scanf("%d",&Ts);
for (; Ts; Ts--){
scanf("%d%d%d",&L,&R,&n);
memset(Q,,,T=,Q[]=L;
memset(f,,;
int x,y;
if (L!=R)
while (H!=T){
H=(H+)%N,x=Q[H],y=D[x]; if (x==R) break;
if (x+y<=n){
) f[x+y]=f[x]+,pus(x+y);
}
){
) f[x-y]=f[x]+,pus(x-y);
}
}
printf("%d\n",f[R]);
}
;
}
T2 异或
一眼就是字典树,然而我把ch数组初值赋了-1然后计数时出现了一些奇妙的事情。。。
事实上,ai^x<=lim这是没有不等式规律的,然而,我们可以把他按位来计算,字典树就很有作用了。
复杂度大概是O(30n)。
code:
#include<cstdio>
#include<cstring>
#include<algorithm>
#define M(a,x) memset(a,x,sizeof a)
#define jug(i,x) (((1<<i)&x)>0)
using namespace std;
;
int n,m,a[N];
struct Trie{
][],va[N*];
void init(){
siz=,M(ch,),M(va,);
}
void insert(int x){
;
; i>=; i--){
bool c=jug(i,x);
if (!ch[u][c]) ch[u][c]=++siz;
u=ch[u][c],va[u]++;
}
}
int query(int x,int lim){
) ;
,ret=n;
; i>=; i--){
bool v=jug(i,x),w=jug(i,lim);
) ret-=va[ch[u][-(w^v)]];
u=ch[u][w^v];
}
return ret;
}
}t;
inline int read(){
; char ch=getchar();
') ch=getchar();
+ch-',ch=getchar();
return x;
}
int main(){
n=read(),m=read(),t.init();
; i<=n; i++)
a[i]=read(),t.insert(a[i]);
for (; m; m--){
int x=read(),L=read(),R=read();
printf());
}
;
}
T3 棋盘
md,看到这题就想表一下。为什么要卡16MB!!!
还不是因为我手贱将f[1<<20]“细心地”变成f[1<<21],然后爆了0.39M内存。。。
好吧,这就是个状压DP,真的水。
code:
%:pragma gcc optimize()
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define LL long long
using namespace std;
;
][];
<<];
LL ans;
int main(){
scanf(<<n);
; i<n; i++) scanf("%s",G[i]);
memset(f,,sizeof f);
; i<n; i++) ][i]==<<i]=;
; r<n; r++){
; j--)
; i<n; i++)
<<i)&j)==)
f[j|(<<i)]=((LL)f[j|(<<i)]+f[j])%TT;
; i<n; i++) <<i]++;
}
; j<M; j++){
;
; i<n; i++) <<i)&j) c++;
if (c==k) ans=(ans+f[j])%TT;
}
printf("%lld",ans%TT);
;
}
总而言之,题目不难,限制变态。。。
[contest 782] 9.7的更多相关文章
- Codeforces 782C. Andryusha and Colored Balloons 搜索
C. Andryusha and Colored Balloons time limit per test:2 seconds memory limit per test:256 megabytes ...
- 树的性质和dfs的性质 Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E
http://codeforces.com/contest/782/problem/E 题目大意: 有n个节点,m条边,k个人,k个人中每个人都可以从任意起点开始走(2*n)/k步,且这个步数是向上取 ...
- 2-sat Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D
http://codeforces.com/contest/782/problem/D 题意: 每个队有两种队名,问有没有满足以下两个条件的命名方法: ①任意两个队的名字不相同. ②若某个队 A 选用 ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E Underground Lab
地址:http://codeforces.com/contest/782/problem/E 题目: E. Underground Lab time limit per test 1 second m ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D. Innokenty and a Football League
地址:http://codeforces.com/contest/782/problem/D 题目: D. Innokenty and a Football League time limit per ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) C Andryusha and Colored Balloons
地址:http://codeforces.com/contest/782/problem/C 题目: C. Andryusha and Colored Balloons time limit per ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Changed
地址:http://codeforces.com/contest/782/problem/B 题目: B. The Meeting Place Cannot Be Changed time limit ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) A. Andryusha and Socks
地址:http://codeforces.com/contest/782/problem/A 题目: A. Andryusha and Socks time limit per test 2 seco ...
- 【codeforces 782C】Andryusha and Colored Balloons
[题目链接]:http://codeforces.com/contest/782/problem/C [题意] 给你一棵树 让你满足要求 ->任意相连的3个节点的颜色不能相同 的情况下进行染色 ...
随机推荐
- Python中的垃圾回收机制
Python的垃圾回收机制 引子: 我们定义变量会申请内存空间来存放变量的值,而内存的容量是有限的,当一个变量值没有用了(简称垃圾)就应该将其占用的内存给回收掉,而变量名是访问到变量值的唯一方式,所以 ...
- windows下远程连接Mysql
使用“Ctrl + R”组合键快速打开cmd窗口,并输入“cmd”命令,打开cmd窗口. 使用“mysql -uroot -proot”命令可以连接到本地的mysql服务. 使用“use mysql” ...
- 【Selenium2】【selenium之 定位以及切换frame(iframe)】
参考:http://blog.csdn.net/huilan_same/article/details/52200586 总有人看不明白,以防万一,先在开头大写加粗说明一下: frameset不用切, ...
- js中setTimeout和clearTimeout的使用
setTimeout,延迟n秒后执行指定代码 clearTimeout,清除计时器 <html> <head> <script type="text/javas ...
- @@identity与SCOPE_IDENTITY的区别
@@identity与SCOPE_IDENTITY的区别 共同点: SCOPE_IDENTITY 和 @@IDENTITY 返回在当前会话中的任何表内所生成的最后一个标识值. 不同处:SCOPE_ID ...
- display: none; 与 jq show方法之间的联系
1. 定义四种常用隐藏元素的方式,然后调用 jq 的 show 方法显示,观察各原先隐藏元素的 display 表现,结合 jq 源码,show 方法设置 元素 display 属性值为 ...
- ZOJ 3965 Binary Tree Restoring
Binary Tree Restoring 思路: 递归 比较a序列和b序列中表示同一个子树的一段区间,不断递归 代码: #include<bits/stdc++.h> using nam ...
- SpringBoot集成ActiveMQ
前面提到了原生API访问ActiveMQ和Spring集成ActiveMQ.今天讲一下SpringBoot集成ActiveMQ.SpringBoot就是为了解决我们的Maven配置烦恼而生,因此使用S ...
- (转+整理)C# BinaryFormatter进行序列化与反序列化
序列化又称串行化,是.NET运行时环境用来支持用户定义类型的流化的机制.其目的是以某种存储形式使自定义对象持久化,或者将这种对象从一个地方传输到另一个地方. .NET框架提供了两种种串行化的方式:1. ...
- redis在php运行时出现错误
我的redis版本:3.2.8. redis安装教程,参考官方网站: https://redis.io/download 在网上多番查找,很多说是配置文件redis.conf中的: # bind 12 ...