CF 610E. Alphabet Permutations
题目:http://codeforces.com/problemset/problem/610/E
如果存在c1,c2在原串相邻且在询问串中c1在c2前面的话,把它们在原串出现次数加起来记作sum,那么n-sum就是答案。
维护一棵线段树,线段树的每个节点存一个k^2的矩阵。
然后修改的话就在线段树上区间修改。。(标记下传的时候要注意不要越界TAT。。。
然后询问的话就k^2搞一下需要被减掉的字符对就好了。。
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define low(x) (x&(-x))
#define maxn 12
#define ll long long
using namespace std;
int n,m,K,ans;
char s[],s2[maxn];
int a[maxn][maxn];
struct data{int mat[maxn][maxn],l,r,tag;
}t[*];
int read(){
int x=,f=; char ch=getchar();
while (!isdigit(ch)) {if (ch=='-') f=-; ch=getchar();}
while (isdigit(ch)){x=x*+ch-''; ch=getchar();}
return x*f;
}
void combine(data &a,data b,data c){
a.l=b.l; a.r=c.r;
rep(i,,K-) rep(j,,K-) a.mat[i][j]=b.mat[i][j]+c.mat[i][j];
a.mat[b.r][c.l]++;
a.tag=-;
}
void build(int i,int l,int r){
int mid=(l+r)/;
if (l==r){
t[i].tag=-; t[i].l=t[i].r=s[l]-'a';
clr(t[i].mat,);
return ;
}
build(i*,l,mid); build(i*+,mid+,r);
combine(t[i],t[i*],t[i*+]);
}
void ps(int i,int l,int r){
if (t[i].tag!=-){
t[i].l=t[i].r=t[i].tag;
clr(t[i].mat,);
t[i].mat[t[i].tag][t[i].tag]=r-l;
if (l!=r) t[i*].tag=t[i*+].tag=t[i].tag;
t[i].tag=-;
}
}
void change(int i,int l,int r,int tl,int tr,int val){
ps(i,l,r);
int mid=(l+r)/;
if (l==tl&&r==tr){
t[i].tag=val;
ps(i,l,r);
return ;
}
if (tr<=mid) {
change(i*,l,mid,tl,tr,val);
ps(i*+,mid+,r);
}
else if (tl>mid){
change(i*+,mid+,r,tl,tr,val);
ps(i*,l,mid);
}
else {
change(i*,l,mid,tl,mid,val);
change(i*+,mid+,r,mid+,tr,val);
}
combine(t[i],t[i*],t[i*+]);
}
int main(){
n=read(); m=read(); K=read();
scanf("%s",s);
build(,,n-);
rep(i,,m){
int op=read();
if (op==){
int l=read()-,r=read()-; scanf("%s",s2);
int now=s2[]-'a';
change(,,n-,l,r,now);
}
else {
ans=n;
scanf("%s",s2);
rep(j,,K-) rep(k,,K-) a[j][k]=;
rep(j,,K-) rep(k,j+,K-) a[s2[j]-'a'][s2[k]-'a']=;
rep(j,,K-) rep(k,,K-) ans-=t[].mat[j][k]*a[j][k];
printf("%d\n",ans);
}
}
return ;
}
CF 610E. Alphabet Permutations的更多相关文章
- Codeforces Round #337 Alphabet Permutations
E. Alphabet Permutations time limit per test: 1 second memory limit per test: 512 megabytes input: ...
- CF数据结构练习
1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取 ...
- CF 715 E. Complete the Permutations
CF 715 E. Complete the Permutations 题目大意:给定两个排列\(p,q\)的一部分.定义两个排列\(p,q\)的距离为使用最少的交换次数使得\(p_i=q_i\).对 ...
- CF 1093 E. Intersection of Permutations
E. Intersection of Permutations 链接 题意: 给定两个序列,询问第一个排列的[l1,r1]和第二个排列[l2,r2]中有多少个共同的数,支持在第二个排列中交换两个数. ...
- cf 251 B Playing with Permutations 暴力 分类讨论
题链;http://codeforces.com/problemset/problem/251/B B. Playing with Permutations time limit per test 2 ...
- CF 463D Gargari and Permutations [dp]
给出一个长为n的数列的k个排列(1 ≤ n ≤ 1000; 2 ≤ k ≤ 5).求这个k个数列的最长公共子序列的长度 dp[i]=max{dp[j]+1,where j<i 且j,i相应的字符 ...
- CF 1093E Intersection of Permutations——CDQ分治
题目:http://codeforces.com/contest/1093/problem/E 只能想到转化成查询一个区间里值在一个范围里的数的个数…… 没有想到这样适合用主席树套树状数组维护.不过据 ...
- 【题解】CF#285 E-Positions in Permutations
挺有收获的一道题ヾ(◍°∇°◍)ノ゙ 恰好为 m ,这个限制仿佛不是很好处理.一般而言,我所了解的恰好为 k 的条件,不是用组合数 / dp状态转移 / 斜率二分就只剩下容斥了.我们可以先处理出 nu ...
- CF D. Number Of Permutations 排列
挺水的一道题~ 拿全排列随便乘一下就好了. #include <cstdio> #include <algorithm> #define N 300004 #define ll ...
随机推荐
- c语言文件分割与合并
一.综述 c语言操作文件通过文件指针FILE*,每个要操作的文件必须打开然后才能读写. 注意事项: @1分割与合并文件最好使用二进制模式即"rb"或"wb",这 ...
- bzoj 4199 [NOI2015]寿司晚宴
Description 为了庆祝 NOI 的成功开幕,主办方为大家准备了一场寿司晚宴.小 G 和小 W 作为参加 NOI 的选手,也被邀请参加了寿司晚宴. 在晚宴上,主办方为大家提供了 n−1 种不同 ...
- jsDOM编程-拖拽层
页面样式代码: <!doctype html><html><head><meta http-equiv="content-type" co ...
- 重启网络服务时 Bringing up interface eth0
重启网络服务时报错: Bringing up interface eth0: Error:Connection activation failed:Device not managed by Net ...
- centOS7 mini配置linux服务器(五) 安装和配置tomcat和mysql
配置java运行环境,少不了服务器这一块,而tomcat在服务器中占据了很大一部分份额,这里就简单记录下tomcat安装步骤. 下载 首先需要下载tomcat7的安装文件,地址如下: http://t ...
- 正则表达式与grep
一.回溯引用 1.将页面中合法的标题找出来,使用回溯引用匹配 (需要使用 -E 或 -P 来扩展grep语法支持) 2.查找连续出现的单词 二.前后查找 (grep 只能使用 -P 选项) 1. 向前 ...
- input上传图片(file),预览图片的两种方法。blob与base64编码
上传图片时一般都需要预览,我一般用这两种方法来实现.base64编码可以直接上传到后台,后台解析下,得到的文件就会比较小了,省去了压缩图片这一步了. //获取对象input file 的图片地址,放进 ...
- MicroPython之TPYBoard v102开发板控制OLED显示中文
转载请以链接形式注明文章来源,公众号:MicroPython玩家汇 0x00前言 之前看到一篇文章是关于TPYBoardv102控制OLED屏显示的,看到之后就想尝试一下使用OLED屏来显示中文.最近 ...
- 常用base.css
ul { list-style: none;}a { text-decoration: none;} body,h1,h2,h3,h4,h5,h6,p,ul,ol,form { margin: 0; ...
- 【APS.NET 框架系列】浅谈ASP.NET 框架
本篇文章稍微偏原理且底层,有一定难度和且比较晦涩. 本篇文章主要是从广度上概括一下,具体的更细粒度的,会在后续的文章中,结合具体的Demo实例分析. 一 .NET框架概述 1.作用:提供了基于. ...