题目: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的更多相关文章

  1. Codeforces Round #337 Alphabet Permutations

    E. Alphabet Permutations time limit per test:  1 second memory limit per test:  512 megabytes input: ...

  2. CF数据结构练习

    1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取 ...

  3. CF 715 E. Complete the Permutations

    CF 715 E. Complete the Permutations 题目大意:给定两个排列\(p,q\)的一部分.定义两个排列\(p,q\)的距离为使用最少的交换次数使得\(p_i=q_i\).对 ...

  4. CF 1093 E. Intersection of Permutations

    E. Intersection of Permutations 链接 题意: 给定两个序列,询问第一个排列的[l1,r1]和第二个排列[l2,r2]中有多少个共同的数,支持在第二个排列中交换两个数. ...

  5. cf 251 B Playing with Permutations 暴力 分类讨论

    题链;http://codeforces.com/problemset/problem/251/B B. Playing with Permutations time limit per test 2 ...

  6. 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相应的字符 ...

  7. CF 1093E Intersection of Permutations——CDQ分治

    题目:http://codeforces.com/contest/1093/problem/E 只能想到转化成查询一个区间里值在一个范围里的数的个数…… 没有想到这样适合用主席树套树状数组维护.不过据 ...

  8. 【题解】CF#285 E-Positions in Permutations

    挺有收获的一道题ヾ(◍°∇°◍)ノ゙ 恰好为 m ,这个限制仿佛不是很好处理.一般而言,我所了解的恰好为 k 的条件,不是用组合数 / dp状态转移 / 斜率二分就只剩下容斥了.我们可以先处理出 nu ...

  9. CF D. Number Of Permutations 排列

    挺水的一道题~ 拿全排列随便乘一下就好了. #include <cstdio> #include <algorithm> #define N 300004 #define ll ...

随机推荐

  1. 通信机制-TCP/IP、Http、Socket的区别

    原文转自:http://blog.csdn.net/axing1991/article/details/45149087 网络由下往上分为 物理层.数据链路层.网络层.传输层.会话层.表示层和应用层. ...

  2. [WinForm]委托应用①——窗口之间方法/控件调用

    不传参数 第二窗口:public partial class Form2 : Form { /// <summary> /// 定义委托 /// </summary> publ ...

  3. MySql监控优化

    MySQL监控   MySQL服务器硬件和OS(操作系统)调优:   1.有足够的物理内存,能将整个InnoDB文件加载到内存里 —— 如果访问的文件在内存里,而不是在磁盘上,InnoDB会快很多. ...

  4. 系统内置委托:Func/Action

    lSystem.Func 代表有返回类型的委托 lpublic delegate TResult  Func<out TResult>(); lpublic delegate TResul ...

  5. 10 Easy Steps to a Complete Understanding of SQL

    原文出处:http://tech.pro/tutorial/1555/10-easy-steps-to-a-complete-understanding-of-sql(已经失效,现在收集如下) Too ...

  6. 自动化测试辅助工具(Selenium IDE等)

    本随表目录 Selenium IDE安装和使用 FireBug安装和使用 FirePath安装和使用   Selenium IDE安装 方式一:打开Firefox-->添加组件-->搜索出 ...

  7. 用C#实现微信“跳一跳”小游戏的自动跳跃助手

    一.前言: 前段时间微信更新了新版本后,带来的一款H5小游戏“跳一跳”在各朋友圈里又火了起来,类似以前的“打飞机”游戏,这游戏玩法简单,但加上了积分排名功能后,却成了“装逼”的地方,于是很多人花钱花时 ...

  8. permission denied for window type 2003

    今天在做系统悬浮窗的时候出现权限拒绝,类型是2003,这里要说下,做系统悬浮窗需要申请权限,6.0以上的 还需要动态申请下,这里我就不过多描述了, 我在申请完权限后仍然不行,这里主要是出现在了这个类型 ...

  9. 利用USearch去除嵌合体(chimeras)

    嵌合体序列指在pcr过程中,两条不同的序列产生杂交扩增的序列,属于人工污染,在ITS和16S分析中,应该首先去除,USearch提供去除嵌合体的功能 usearch -uchime_ref reads ...

  10. (class file version 53.0), Java Runtime versions up to 52.0错误的解决方法

    遇到这个错误是在Apache Tomcat上部署应用程序的时候遇到的,具体的错误描述是: java.lang.UnsupportedClassVersionError: HelloWorld has ...