cf1000F. One Occurrence(线段树 set)】的更多相关文章

这题我是离线做的 设i位置的数上次出现的位置是pre[i](如果第一次出现那就是0) 可以想到,用线段树维护一个区间的pre的最小值,如果它小于区间左端点,那这个数就是一个合法的答案 但直接这样做是错的 考虑1,2,3,4,[1,1],5,虽然前一个1的pre在区间外面,但他后面还有一个1啊 所以可以按照询问的右端点排序,推着来维护这个最小值 具体来说,对于i,先把i位置的值改成pre[i],然后如果有pre[i],那把pre[i]位置的值改成inf(一开始都要初始化成inf) 然后再查的话,我…
题意 题目链接 Sol (真后悔没打这场EDU qwq) 首先把询问离线,预处理每个数的\(pre, nxt\),同时线段树维护\(pre\)(下标是\(pre\),值是\(i\)),同时维护一下最大值 那么每次在\((1, l - 1)\)内查询最大值,如果最大值\(>= l\),那么说明合法 但是\(pre\)可能会有相同的情况(0),直接开个set维护一下 然后用vector对\(nxt\)维护一个类似差分的东西,在\(nxt_i\)的位置删除掉\(i\)的影响 // luogu-judg…
layout: post title: HDU-6704 K-th occurrence (后缀自动机father树上倍增建权值线段树合并) author: "luowentaoaa" catalog: true tags: mathjax: true - kuangbin - 字符串 " target="_blank" style="font-size:24px;">传送门 题意 给出一个长度为\(n\)字符串\(s\), \(…
题目描述 给定字符串\(S(|S|\le10^5)\),对其每个前缀求出如下的统计量: 对该字符串中的所有子串,统计其出现的次数,求其平方和. Sample Input: aaa Sample Output: 详细题解 1.只求整个串的答案的解决方案 首先可一眼想到后缀自动机. 对后缀自动机上每个状态,定义endpos为所有能走到该状态的子串中子串右端点的取值集合.如果求出其endpos位置个数\(x\),那么就能求得该状态对答案的贡献,为\(x^2*(r-l+1)\),其中\(l,r\)分别为…
You are given an array aa consisting of nn integers, and qq queries to it. ii-th query is denoted by two integers lili and riri. For each query, you have to find any integer that occurs exactly once in the subarray of aa from index lili to index riri…
题意:给你一个长度为n的字符串和m组询问,每组询问给出l,r,k,求s[l,r]的第k次出现的左端点. 解法一: 求出后缀数组,按照排名建主席树,对于每组询问二分或倍增找出主席树上所对应的的左右端点,求第k大的下标即可. #include<bits/stdc++.h> using namespace std; typedef long long ll; ,mod=; char buf[N]; ],Log[N],m; void Sort(int* x,int* y,int m) { ; i<…
大意: 给定串s, q个询问(l,r,k), 求子串s[l,r]的第kk次出现位置. 这是一篇很好的题解: https://blog.csdn.net/sdauguanweihong/article/details/100063096 加点个人: 我对上面的题解更为详细的解释下: 后缀数组处理出来的heigth[] 数组 有个这样的性质: 对于排名 a 的后缀字符串 与排名 b 的后缀字符串  ,他们的最长公共前缀的长度为 min{heigth[a+1],heigth[a+2],heigth[b…
解题思路: fail树上用权值线段树合并求right/endpos集合,再用倍增找到待查询串对应节点,然后权值线段树求第k大. #include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=1e5+5; int n,q; char s[maxn]; namespace SegTree{ int sum[maxn*100],L[maxn*100],R[maxn*100]; int tot1; i…
Problem Description You are given a string S consisting of only lowercase english letters and some queries.For each query (l,r,k), please output the starting position of the k-th occurence of the substring SlSl+1...Sr in S. Input The first line conta…
题目链接 problem Recently George is preparing for the Graduate Record Examinations (GRE for short). Obviously the most important thing is reciting the words. Now George is working on a word list containing N words. He has so poor a memory that it is too…