博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Magic FZU - 2280 无脑HASH暴力
阅读量:5103 次
发布时间:2019-06-13

本文共 3605 字,大约阅读时间需要 12 分钟。

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

15abracadabra 2adbra 1bra 3abr 3br 252 32 51 2 52 32 2

Sample Output

3121

题意:

给n个长度<=1000的字符串S[i](仅由小写字母构成),每个字符串有权值w[i]

有两种操作
2 k 选中第k个字符串,问你有多少个字符串满足w[i]<=w[k]而且S[k]是S[i]的后缀
1 k y 把第k个字符串的权值修改为

 

暴力HASH 预处理下后缀

然后暴力查询

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #define pi acos(-1.0)13 #define eps 1e-614 #define fi first15 #define se second16 #define lson l,m,rt<<117 #define rson m+1,r,rt<<1|118 #define bug printf("******\n")19 #define mem(a,b) memset(a,b,sizeof(a))20 #define fuck(x) cout<<"["<
<<"]"<
= b; i--)29 #define FRL(i,a,b) for(i = a; i < b; i++)30 #define FRLL(i,a,b) for(i = a; i > b; i--)31 #define FIN freopen("DATA.txt","r",stdin)32 #define gcd(a,b) __gcd(a,b)33 #define lowbit(x) x&-x34 #pragma comment (linker,"/STACK:102400000,102400000")35 using namespace std;36 typedef long long LL;37 typedef unsigned long long ULL;38 const int INF = 0x7fffffff;39 const int mod = 1e9 + 7;40 const int maxn = 1e3 + 10;41 int t, n, m, val[maxn], len[maxn];42 char mp[maxn][maxn];43 vector
cnt[maxn];44 ULL HA[maxn][maxn], p[maxn], seed = 99959;45 ULL getcnt(int id, int l, int r) {46 return HA[id][r] - HA[id][l - 1] * p[r - l + 1];47 }48 void init() {49 p[0] = 1;50 for (int i = 1 ; i < maxn ; i++) p[i] = p[i - 1] * seed;51 for (int i = 1 ; i <= n ; i++) {52 HA[i][0] = 0;53 for (int j = 1 ; j <= len[i] ; j++) {54 HA[i][j] = HA[i][j - 1] * seed + mp[i][len[i] - j + 1];55 }56 }57 for (int i = 1 ; i <= n ; i++) {58 cnt[i].push_back(i);59 for (int j = i + 1 ; j <= n ; j++ ) {60 if (len[i] == len[j] && HA[i][len[i]] == HA[j][len[j]]) cnt[i].push_back(j), cnt[j].push_back(i);61 else if (len[i] > len[j] && HA[j][len[j]] == getcnt(i, 1, len[j] )) cnt[j].push_back(i);62 else if (len[i] < len[j] && HA[i][len[i]] == getcnt(j, 1, len[i] )) cnt[i].push_back(j);63 }64 }65 }66 int main() {67 //FIN;68 sf(t);69 while(t--) {70 sf(n);71 for (int i = 1 ; i <= n ; i++) {72 cnt[i].clear();73 scanf("%s%d", mp[i] + 1, &val[i]);74 len[i] = strlen(mp[i] + 1);75 }76 init();77 sf(m);78 while(m--) {79 int op, x, y;80 sf(op);81 if (op == 1) {82 sff(x, y);83 val[x] = y;84 } else {85 sf(x);86 int ans = 0;87 for (int i = 0 ; i < cnt[x].size() ; i++)88 if (val[cnt[x][i]] <= val[x]) ans++;89 printf("%d\n", ans);90 }91 }92 }93 return 0;94 }

 

 

转载于:https://www.cnblogs.com/qldabiaoge/p/9515687.html

你可能感兴趣的文章
自我审视
查看>>
unix c 08
查看>>
HDU 5977 Garden of Eden(点分治求点对路径颜色数为K)
查看>>
flume与log4j的整合
查看>>
BM25算法的python实现
查看>>
Entity FrameWork利用Database.SqlQuery<T>执行存储过程并返回参数
查看>>
如何创建 Visual Studio 2017 RC 离线安装包
查看>>
时间安排还是很不合理
查看>>
Django Ajax学习一
查看>>
OGRE学习笔记(一)通过例子了解场景管理器---------地形创建
查看>>
51nod 1185 || 51nod 1072 威佐夫博弈
查看>>
DataGridView的行的字体颜色变化
查看>>
java.nio异步线程安全的IO
查看>>
(网上摘抄)云标签
查看>>
记录-时间日期
查看>>
便签:
查看>>
JS function 函数基本定义方法
查看>>
Java再学习——关于ConcurrentHashMap
查看>>
bzoj3944 Sum
查看>>
后缀表达式/逆波兰表达式
查看>>