[CF580E]Kefa and Watch】的更多相关文章

题目大意: 维护一个由'0'~'9'构成的字符串,支持以下两种操作: 1.将指定区间内的所有字符修改为同一指定字符. 2.询问$x$是否为指定区间内的循环节. 思路: 建立一棵线段树,维护每个子串的哈希值. 实现细节: 1.Lazy-tag需要初始化成$-1$,因为$0$也是字符串中的元素,会混淆. 2.预处理出seed的$n$次幂及其前缀和,可以优化常数. 3.查询时需要合并两个区间的哈希值,需要考虑$mid<r$和$mid\geq r$两种情况. 其它: 这题调不出的时候打了一个暴力对拍,加…
题意 $n$个数的序列,$m + k$种操作 1.$l , r, k$把$l - r$赋值为$k$ 2.$l, r, d$询问$l - r$是否有长度为$d$的循环节 Sol 首先有个神仙结论:若询问区间为$(l, r, d)$,则只需判断$(l + d, r)$和$(l, r - d )$是否相同 证明可以用归纳法. 然后线段树维护一下字符串hash值,维护一个区间覆盖的标记就好了 注意赋值的时候有$0$的情况,因此开始的标记不能为$0$ #include<cstdio> #include&…
线段树+哈希[CF580E]Kefa and Watch Description \(n\)个数的字符串,\(m + k\)个操作 1 l r k把\(l - r\)赋值为\(k\) 2 l r d询问\(l - r\)是否有长度为\(d\)的循环节 \(n \leq 10^5, m + k \leq 10^5, d \leq 10\) Input 第一行为三个整数\(n,m,k\) 第二行为一个\(n\)个数的字符串. 接下来\(m+k\)行每行对应一种操作. Output 对于每一个\(2\…
Description When Kefa came to the restaurant and sat at a table, the waiter immediately brought him the menu. There were n dishes. Kefa knows that he needs exactly m dishes. But at that, he doesn't want to order the same dish twice to taste as many d…
题目链接: 传送门 Kefa and Company time limit per test:2 second     memory limit per test:256 megabytes Description Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has n friends, each friend will agree to…
#include<bits/stdc++.h> #define max 100005 using namespace std; int cats[max]; vector<int>tree[max]; int visit[max]; ; int n,m; vector<int>::iterator it; void init() { ans=; memset(visit,,sizeof(visit)); ;i<n;i++) tree[i].clear(); mem…
B - Kefa and Company Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 580B Description Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa…
题目链接: 题目 D. Kefa and Dishes time limit per test:2 seconds memory limit per test:256 megabytes 问题描述 When Kefa came to the restaurant and sat at a table, the waiter immediately brought him the menu. There were n dishes. Kefa knows that he needs exactly…
E. Kefa and Watch Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/problem/E Description One day Kefa the parrot was walking down the street as he was on the way home from the restaurant when he saw something glittering b…
C. Kefa and Park Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/problem/C Description Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree con…