A  CodeChef - KSPHERES

中文题意  Mandarin Chinese

Eugene has a sequence of upper hemispheres and another of lower hemispheres. The first set consists of N upper hemispheres indexed 1 to N and the second has M lower hemispheres indexed 1 to M. The hemispheres in any sequence can have different radii.

He is now set out on building spheres using them. To build a sphere of radius R, he must take one upper half of the radius R and one lower half of the radius R. Also, he can put a sphere into a bigger one and create a sequence of nested concentric spheres. But he can't put two or more spheres directly into another one.

Examples:


If there is a sequence of (D+1) nested spheres, we can call this sequence as a D-sequence.


Eugene has to find out how many different X-sequence are possible (1 <= X <= C). An X sequence is different from another if the index of any of the hemisphere used in one X-sequence is different from the other. Eugene doesn't know how to do it, so Chef agreed to help him. Of course, Chef is too busy now and he asks you to help him.

Input

The first line contains a three integers: N denoting the number of upper sphere halves, M denoting the number of lower sphere halves and C.

The second line contains N space-separated integers U1U2, ..., UN denoting the radii of upper hemispheres.

The third line contains M space-separated integers L1L2, ..., LM denoting the radii of lower hemispheres.

Output

Output a single line containing C space-separated integers D1D2, ..., DC, where Diis the number of ways there are to build i-sequence in modulo 109+7.

Constraints

  • 1 ≤ N ≤ 105
  • 1 ≤ M ≤ 105
  • 1 ≤ C ≤ 103
  • 1 ≤ Ui ≤ C
  • 1 ≤ Li ≤ C

Subtasks

  • Subtask 1: 1 ≤ N, M, C ≤ 10 - 15 points
  • Subtask 2: 1 ≤ N, M, C ≤ 100 - 25 points
  • Subtask 3: Original constraints - 60 points

Example

Input:
3 4 3
1 2 3
1 1 3 2
Output:
5 2 0

Explanation

We can build spheres with such radii:

R=1 and there are 2 ways to do it. (We can choose any of 2 lower hemispheres with R=1)

R=2 and there is 1 way to do it.

R=3 and there is 1 way to do it.

We can build these 1-sequences:

1->2 and there are 2 ways to do it. ( sphere with radius 1 is inside sphere with radius 2, we can choose any of 2 ways of building sphere with radius 1)

1->3 and there are 2 ways to do it.

2->3 and there is 1 way to do it.

2 + 2 + 1 = 5

We can build these 2-sequences:

1->2->3 and there are 2 ways to do it.

We can't build 3-sequences, because we don't have 4 spheres of different radii.

Mandarin Chinese

题解:当时这题考试来着,想了10分钟,手推了一下,发现对于每个i的答案就是这c个数取i个的组合,然后我就暴力求每个数的组合了。。。居然还打了半小时==,以为有5s时限能卡过,但没想到只有15分。

纪念一下。。

 var
n,m,c,i,j,k,tot,l:longint;
ans:int64;
vis:array[..]of boolean;
a,b,t,rt,d,sum,num:array[..]of longint;
procedure dfs(s:longint);
var i,su:longint;
begin
if s=k+ then
begin
su:=;
for i:= to k do su:=su*d[num[i]] mod ;
// for i:= to k do write(num[i],' ');
// writeln;
ans:=(ans+su)mod ;
exit;
end else
for i:=num[s-]+ to c do
begin
num[s]:=i;
vis[i]:=true;
dfs(s+);
vis[i]:=false;
end;
end;
begin
readln(n,m,c);
for i:= to n do begin read(a[i]); inc(t[a[i]]);end;
readln;
for i:= to m do begin read(b[i]); inc(rt[b[i]]);end;
for i:= to c do
begin
d[i]:=(t[i]*rt[i]) mod ;
end;
// for i:= to c do writeln(d[i]);
for i:= to c do
begin
k:=i+;
if k>c then begin write(,' ');continue; end;
ans:=;
for l:= to do num[i]:=;
for l:= to do vis[i]:=false;
dfs(); write(ans mod ,' ');
end; end.

考完之后询问大佬,发现可以dp? 类似于递推,再回去看我的那些组合,后面的组合包含前面的,前面是后面的子问题,用dp思想,f[i][j]表示套i个圆,当前最大的圆的半径是j的方案数。

(其实dp方程表示出来的东西要能表示整个题目的问题和答案)递推方程就是f[i,j]=f[i,j-1]+f[i-1,j-1]*d[i]  f[i,j-1]是继承前面一个圈的,f[i-1,j-1]是当前这个圈的方案数。

 var
n,m,c,i,j,k,tot,l,modd:longint;
ans:int64;
f:array[..,..]of int64;
vis:array[..]of boolean;
a,b,t,rt,d,sum,num:array[..]of longint;
begin
modd:=;
readln(n,m,c);
for i:= to n do begin read(a[i]); inc(t[a[i]]);end;
readln;
for i:= to m do begin read(b[i]); inc(rt[b[i]]);end;
for i:= to c do
begin
d[i]:=(t[i]*rt[i]) mod ;
end;
// for i:= to c do writeln(d[i]);
for i:= to c do f[][i]:=f[,i-]+d[i];
for i:= to c- do
for j:= to c do
begin
f[i,j]:=(f[i,j-]+(f[i-,j-]*d[j]) mod modd)mod modd;
end;
for i:= to c do write(f[i,c],' ');
end.

明显短了不少==

B - Sereja and Commands

中文题意 mandarin chinese

题解:因为每次都是加1,而且操作如此多次,暴力直接算会超时,操作多次用递归计算又很麻烦,所以。。想到差分。比如你要在x~y区间上加1,操作就是在a[x]位置+1,在a[y-1]的位置-1

最后从1~n扫一遍,a[i]=a[i]+a[i-1]就行了。另外在操作2的时候,你需要从后往前搜(后面不影响前面),也要用差分来做,不然只有50分,所以这个题目,需要用到两个差分来做,

最最后,还要注意负数取mod, (x mod INF+INF)mod INF    (INF为模数)

 var
a,q,x,y,id,b:array[-..]of int64;
t,n,m:int64;
i,j,l:longint;
modd:longint;
begin
readln(t);
modd:=+;
for l:= to t do
begin
//fillchar(q,sizeof(q),);
// fillchar(x,sizeof(x),);
// fillchar(y,sizeof(y),);
fillchar(b,sizeof(b),);
fillchar(a,sizeof(a),);
readln(n,m);
for i:= to m do
begin
readln(q[i],x[i],y[i]);
inc(id[i]);
end;
b[m]:=;
for i:=m downto do
begin
b[i]:=(b[i]+b[i+])mod modd;
if q[i]= then
begin
// for j:=x[i] to y[i] do id[j]:=((id[j]+id[i])mod modd+modd)mod modd;
b[y[i]]:=(b[y[i]]+b[i])mod modd;
b[x[i]-]:=((b[x[i]-]-b[i])mod modd+modd)mod modd;
// id[i]:=;
end;
end;
for i:= to m do
if q[i]= then
begin
a[x[i]]:=((a[x[i]]+b[i])mod modd+modd)mod modd;
a[y[i]+]:=((a[y[i]+]-b[i])mod modd+modd)mod modd;
end;
for i:= to n do
begin
a[i]:=((a[i-]+a[i])mod modd+modd)mod modd;
write(a[i],' ');
end;
writeln;
end;
end.

C - Blocked websites

中文题意  mandarin chinese

题意:给你若干个英文单词,前带+号的要保留,前带-号的要舍去,舍去的方法是用 前缀过滤器,就是以此为前缀的单词会被舍去。求出最少需要的个数和输出该前缀。如果做不到就输出-1.

题解:考试的时候当然想不出了。考后问大佬,可以用字典树做?那就来普及一下字典树吧。据我的理解,就是把一个字符串存入树中,每个节点是一个字符(char),插入字符串时,如果当前字符树中有,树中该字符num[ ]++,然后遍历下去,若没有,就新开一个节点记录,最后应该是一个森林。

在此题中,字典树建好后,你需要再开两个数组,ban 和 admit 。分别记录该节点字符舍去和保留的数目。

最后从根节点 dfs一遍,若遇到admit[now]=0 时,则说明该节点下去没有需保留的单词了,那就返回该节点被ban的字符个数和字符串(前缀),还有做不到的

情况是返回ban的字符个数小于总的要被ban个数,则输出-1.(情理之中,不需要想太多)

 var
n,m,i,ssum,sum,tot,bannum,c,k:longint;
s:ansistring;
ans:array[..]of ansistring;
tree:array[..,..]of longint;
adm,ban:array[..]of longint;
7 procedure insert(s1:ansistring;c:longint);// 字典树建树 模板
8 var len,now,val,i:longint;
9 begin
10 now:=0;val:=0;len:=length(s1);
11 for i:=1 to len do
12 begin
13 val:=ord(s1[i])-ord('a');
14
15 if tree[now,val]=0 then
16 begin
17 inc(tot);
18 tree[now,val]:=tot;
19 end;
20 now:=tree[now,val];// 注意,now<>tot 如果字典树中有该字符,就不需要++tot了,直接指为它就好
21 // inc(num[now]);
22
23 if c=1 then inc(adm[now]) else inc(ban[now]);
24
25 end;
// endd[now]:=true;
26 end;
procedure dfs(u:longint;nows:ansistring);
var i:longint;
begin
// writeln(nows);
// writeln(u);
if adm[u]= then
begin
inc(sum);
ans[sum]:=nows;
ssum:=ssum+ban[u];
exit;
end;
if ban[u]= then exit;
for i:= to do // 0 所表示的字符为'a' ,从'a'~'z'
begin
if tree[u,i]<> then dfs(tree[u,i],nows+chr(i+ord('a'))); end;
end; begin
readln(n);
for i:= to n do
begin
readln(s);
if s[]='+' then c:= else begin c:=; inc(bannum); end;
// writeln(copy(s,,length(s)-));
insert(copy(s,,length(s)-),c);
end;
adm[]:=-; ban[]:=-;//初始化,根节点不参与
dfs(,'');
// writeln(adm[]);
// writeln(ans[]);
if ssum<bannum then writeln(-) else
begin
writeln(sum);
for i:= to sum do writeln(ans[i]);
end;
end.

contest0 from codechef的更多相关文章

  1. 【BZOJ-3514】Codechef MARCH14 GERALD07加强版 LinkCutTree + 主席树

    3514: Codechef MARCH14 GERALD07加强版 Time Limit: 60 Sec  Memory Limit: 256 MBSubmit: 1288  Solved: 490 ...

  2. 【BZOJ4260】 Codechef REBXOR 可持久化Trie

    看到异或就去想前缀和(⊙o⊙) 这个就是正反做一遍最大异或和更新答案 最大异或就是很经典的可持久化Trie,从高到低贪心 WA: val&(1<<(base-1))得到的并不直接是 ...

  3. codechef 两题

    前面做了这场比赛,感觉题目不错,放上来. A题目:对于数组A[],求A[U]&A[V]的最大值,因为数据弱,很多人直接排序再俩俩比较就过了. 其实这道题类似百度之星资格赛第三题XOR SUM, ...

  4. codechef January Challenge 2014 Sereja and Graph

    题目链接:http://www.codechef.com/JAN14/problems/SEAGRP [题意] 给n个点,m条边的无向图,判断是否有一种删边方案使得每个点的度恰好为1. [分析] 从结 ...

  5. BZOJ3509: [CodeChef] COUNTARI

    3509: [CodeChef] COUNTARI Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 339  Solved: 85[Submit][St ...

  6. CodeChef CBAL

    题面: https://www.codechef.com/problems/CBAL 题解: 可以发现,我们关心的仅仅是每个字符出现次数的奇偶性,而且字符集大小仅有 26, 所以我们状态压缩,记 a[ ...

  7. CodeChef FNCS

    题面:https://www.codechef.com/problems/FNCS 题解: 我们考虑对 n 个函数进行分块,设块的大小为S. 每个块内我们维护当前其所有函数值的和,以及数组中每个元素对 ...

  8. codechef Prime Distance On Tree(树分治+FFT)

    题目链接:http://www.codechef.com/problems/PRIMEDST/ 题意:给出一棵树,边长度都是1.每次任意取出两个点(u,v),他们之间的长度为素数的概率为多大? 树分治 ...

  9. BZOJ 3221: [Codechef FEB13] Obserbing the tree树上询问( 可持久化线段树 + 树链剖分 )

    树链剖分+可持久化线段树....这个一眼可以看出来, 因为可持久化所以写了标记永久化(否则就是区间修改的线段树的持久化..不会), 结果就写挂了, T得飞起...和管理员拿数据调后才发现= = 做法: ...

随机推荐

  1. (生产)vuex - 状态管理

    参考:https://vuex.vuejs.org/zh-cn/ 安装 直接下载 / CDN 引用 https://unpkg.com/vuex在 Vue 之后引入 vuex 会进行自动安装:< ...

  2. canvas剪辑区域

  3. Excel 解析 (大文件读取)BingExcel

    最近在整理一个excel读取与写出的orm框架.使用的saxreader方式,支持百万级别的excel读取. 并且在通常使用中提供了监听的读取方式.如感兴趣的朋友可以稍微了解下 ,项目地址https: ...

  4. [原创] Debian9上配置软件阵列

    序言 软阵列是用软件实现的磁盘阵列. 准备工作 1. 更新系统 没啥,就他喵想用个最新的. apt update && apt upgrade 2. 安装mdadm 如果系统没有自带m ...

  5. TP5.1:实现分页

    前提: (1)为了让分页变得更加好看,我的案例加载了bootstrap和jq的文件,具体操作请参考:http://www.cnblogs.com/finalanddistance/p/9033916. ...

  6. QT Creater 配色方案及下载

    打开QT Creater的工具--选项--文本编辑器--字体和颜色,复制一份配色方案:Vim (dark) ->Vim (dark) (copy) 更改想更改的任何内容的配色.其中,修改后的文件 ...

  7. 关于tcp的keepalive

    先记录几个要点 只能用在面向连接的tcp中,对应对端的非正常关闭有效(对端服务器重启这种,也是正常关闭,FIN RST包都算) 只要是写入到缓冲区就认为OK,所以UDP不适合,所以如果有正常的网络交互 ...

  8. win10启动项添加方法

    1.添加或删除启动文件夹下的快捷方式实现开机自启动 我们可以直接将应用软件的快捷方式拖到启动文件夹里,下次开机时便会自动运行这些软件. 不需要开机启动某些软件了就将启动文件夹里的该软件的快捷方式删除掉 ...

  9. css3阴影 box-shadow

    语法 box-shadow:X轴偏移量 y轴偏移量 [阴影模糊半径] [阴影扩展半径] [阴影颜色] [投影方式] 参数介绍: 注:inset 可以写在参数的第一个或最后一个,其它位置是无效的. 阴影 ...

  10. Spring boot 集成三种定时任务方式

    三种定时任务方式分别为 org.springframework.scheduling.annotation.Scheduled java.util.concurrent.ScheduledExecut ...