Kim is a magician, he can use n kinds of magic, number from 1 to n. We use string Si to describe magic i. Magic Si will make Wi points of damage. Note that Wi may change over time.

Kim obey the following rules to use magic:

Each turn, he picks out one magic, suppose that is magic Sk, then Kim will use all the magic i satisfying the following condition:

1. Wi<=Wk

2. Sk is a suffix of Si.

Now Kim wondering how many magic will he use each turn.

Note that all the strings are considered as a suffix of itself.

Input

First line the number of test case T. (T<=6)

For each case, first line an integer n (1<=n<=1000) stand for the number of magic.

Next n lines, each line a string Si (Length of Si<=1000) and an integer Wi (1<=Wi<=1000), stand for magic i and it’s damage Wi.

Next line an integer Q (1<=Q<=80000), stand for there are Q operations. There are two kinds of operation.

“1 x y” means Wx is changed to y.

“2 x” means Kim has picked out magic x, and you should tell him how many magic he will use in this turn.

Note that different Si can be the same.

Output

For each query, output the answer.

Sample Input

1
5
abracadabra 2
adbra 1
bra 3
abr 3
br 2
5
2 3
2 5
1 2 5
2 3
2 2

Sample Output

3
1
2
1

题意:

给n个长度<=1000的字符串S[i](仅由小写字母构成),每个字符串有权值w[i]
有两种操作
2 k 选中第k个字符串,问你有多少个字符串满足w[i]<=w[k]而且S[k]是S[i]的后缀
1 k y 把第k个字符串的权值修改为

暴力HASH 预处理下后缀

然后暴力查询

 #include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define eps 1e-6
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define bug printf("******\n")
#define mem(a,b) memset(a,b,sizeof(a))
#define fuck(x) cout<<"["<<x<<"]"<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("DATA.txt","r",stdin)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) x&-x
#pragma comment (linker,"/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 0x7fffffff;
const int mod = 1e9 + ;
const int maxn = 1e3 + ;
int t, n, m, val[maxn], len[maxn];
char mp[maxn][maxn];
vector<int>cnt[maxn];
ULL HA[maxn][maxn], p[maxn], seed = ;
ULL getcnt(int id, int l, int r) {
return HA[id][r] - HA[id][l - ] * p[r - l + ];
}
void init() {
p[] = ;
for (int i = ; i < maxn ; i++) p[i] = p[i - ] * seed;
for (int i = ; i <= n ; i++) {
HA[i][] = ;
for (int j = ; j <= len[i] ; j++) {
HA[i][j] = HA[i][j - ] * seed + mp[i][len[i] - j + ];
}
}
for (int i = ; i <= n ; i++) {
cnt[i].push_back(i);
for (int j = i + ; j <= n ; j++ ) {
if (len[i] == len[j] && HA[i][len[i]] == HA[j][len[j]]) cnt[i].push_back(j), cnt[j].push_back(i);
else if (len[i] > len[j] && HA[j][len[j]] == getcnt(i, , len[j] )) cnt[j].push_back(i);
else if (len[i] < len[j] && HA[i][len[i]] == getcnt(j, , len[i] )) cnt[i].push_back(j);
}
}
}
int main() {
//FIN;
sf(t);
while(t--) {
sf(n);
for (int i = ; i <= n ; i++) {
cnt[i].clear();
scanf("%s%d", mp[i] + , &val[i]);
len[i] = strlen(mp[i] + );
}
init();
sf(m);
while(m--) {
int op, x, y;
sf(op);
if (op == ) {
sff(x, y);
val[x] = y;
} else {
sf(x);
int ans = ;
for (int i = ; i < cnt[x].size() ; i++)
if (val[cnt[x][i]] <= val[x]) ans++;
printf("%d\n", ans);
}
}
}
return ;
}
												

Magic FZU - 2280 无脑HASH暴力的更多相关文章

  1. I - Magic FZU - 2280 (字符串hash)

    题目链接: I - Magic FZU - 2280 学习链接: FZU - 2280 I - Magic 题目大意: 给你nn个字符串,每个字符串有一个值ww,有qq次询问,一共两种操作:一是“1, ...

  2. 【原】无脑操作:express + MySQL 实现CRUD

    基于node.js的web开发框架express简单方便,很多项目中都在使用.这里结合MySQL数据库,实现最简单的CRUD操作. 开发环境: IDE:WebStorm DB:MySQL ------ ...

  3. Go语言及Web框架Beego环境无脑搭建

    [原]Go语言及Web框架Beego环境无脑搭建 本文涉及软件均以截至到2013年10月12日的最新版本为准 1. 相关软件准备: 1) go1.2rc1.windows-386.msi,对应32位w ...

  4. 【原】无脑操作:eclipse + maven搭建SSM框架

    网上看到一些Spring + Spring MVC + MyBatis框架的搭建教程,不是很详细或是时间久远了,自己动手整一个简单无脑的! 0.系统环境 1)Windows 10 企业版 2)JDK ...

  5. 计蒜客 无脑博士 bfs

    题目链接无脑博士的试管们 思路:直接模拟倒水过程即可,但是需要记忆判断当前的情况是否已经处理过.dfs和bfs都ok AC代码 #include <cstdio> #include < ...

  6. CodeForces 909E Coprocessor(无脑拓扑排序)

    You are given a program you want to execute as a set of tasks organized in a dependency graph. The d ...

  7. 【原】无脑操作:ElasticSearch学习笔记(01)

    开篇来自于经典的“保安的哲学三问”(你是谁,在哪儿,要干嘛) 问题一.ElasticSearch是什么?有什么用处? 答:截至2018年12月28日,从ElasticSearch官网(https:// ...

  8. 【原】无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础授权权限

    上一篇<[原]无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础认证权限>介绍了实现Shiro的基础认证.本篇谈谈实现 ...

  9. 【原】无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础认证权限

    开发环境搭建参见<[原]无脑操作:IDEA + maven + SpringBoot + JPA + Thymeleaf实现CRUD及分页> 需求: ① 除了登录页面,在地址栏直接访问其他 ...

随机推荐

  1. 剑指offer-从上往下打印二叉树22

    题目描述 从上往下打印出二叉树的每个节点,同层节点从左至右打印. class Solution: # 返回从上到下每个节点值列表,例:[1,2,3] def PrintFromTopToBottom( ...

  2. priority_queue(优先队列):排序不去重

    C++优先队列类似队列,但是在这个数据结构中的元素按照一定的断言排列有序. 头文件:#include<queue> 参数:priority_queue<Type, Container ...

  3. php 安全方面面试题

    1 MySQL数据库作发布系统的存储,一天五万条以上的增量,预计运维三年,怎么优化? a. 设计良好的数据库结构,允许部分数据冗余,尽量避免join查询,提高效率.b. 选择合适的表字段数据类型和存储 ...

  4. Eclipse 安装SVN、Maven插件

    1先安装subeclipse插件就是svn svn - http://subclipse.tigris.org/update_1.6.x 我这里是灰色的说明我安装过了这里只是截图说明下,我就不继续安装 ...

  5. net::ERR_ABORTED ,引入js文件出现报错的解决方法

    在head头里面添加 <mvc:annotation-driven enable-matrix-variables="true"></mvc:annotation ...

  6. rsync+inotify实现实时同步,自动触发同步文件

    本文参考来自:http://chocolee.blog.51cto.com/8158455/1400596 我的需求和他的略有不同,同时做了一下更改,如下: 需求:两台机器相互为主备,搭建相同的两个服 ...

  7. jQuery File Upload文件上传插件简单使用

    前言 开发过程中有时候需要用户在前段上传图片信息,我们通常可以使用form标签设置enctype=”multipart/form-data” 属性上传图片,当我们点击submit按钮的时候,图片信息就 ...

  8. C语言实训——扑克牌洗牌程序

    说明此程序本来是21点扑克程序的一个被调函数,在这里我单独将它拿出来作为一个小程序. #include<stdio.h> #include<time.h> #include&l ...

  9. 11.24Daily Scrum(4)

    人员 任务分配完成情况 明天任务分配 王皓南 实现网页上视频浏览的功能.研究相关的代码和功能.1007 实现视频浏览的功能 申开亮 实现网页上视频浏览的功能.研究相关的代码和功能.1008 实现视频浏 ...

  10. ueditor百度编辑器的赋值方法

    示例: http://ueditor.baidu.com/website/onlinedemo.html 引用代码: window.UMEDITOR_HOME_URL = $CONFIG['domai ...