2018/8/8

一天做了3道题...进步了一道..

Kojima Genta is one of the best friends of Conan, and the fattest one!

Everyone believes that Genta is just thinking about food. So, he wants to prove the opposite. So, his friends challenged him in a game. Genta's friends will give him a string s of length n, and m update operations. At each update operation, an integer p (1 ≤ p ≤ n) and a lowercase English letter c will be given to Genta, and he is asked to change the pth letter in the string s to the letter c.

Conan explained to Genta that an update operation is said to be beautiful if the string s was a palindrome string after the update operation has been executed.

Genta task is to count the number of beautiful update operations. Genta wants to win in this game no matter what this will cost because his friends promised him that the food will be at their expense throughout the week if he solved the task. Can you help Genta by solving his task?

Input

The first line contains an integer T (1 ≤ T ≤ 50), in which T is the number of test cases.

The first line of each test cases contains two integers n and m (1 ≤ n, m ≤ 105), in which n is the length of the string s and m is the number of update operations. The second line of each test cases contains a string s of length n consisting of lowercase English letters only. Then m lines follow, each line contains an integer pand a lowercase English letter c (1 ≤ p ≤ n), giving the update operations.

The sum of n and m overall test cases does not exceed 7 × 105 for each.

Output

For each test case, print a single line containing the number of beautiful update operations.

Example

Input

1
10 7
abcdefdcba
5 x
6 x
4 d
2 d
3 y
8 y
9 d

Output

3

Note

A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, such as "madam" or "racecar".

In the first test case, the string s will be updated as follow:

abcdefdcba  abcdxfdcba  abcdxxdcba  abcdxxdcba  adcdxxdcba  adydxxdcba adydxxdyba  adydxxdyda.

There are 3 beautiful update operations, which are the 2rd, 3th, and 7th operations.

 

水题不解释

上代码

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
char s[100005];
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        cin>>(s+1);
        int t=n/2;
        int num=0;
        int ans=0;

        for(int i=1;i<=t;i++)
            if(s[i]==s[n+1-i])num++;
        for(int i=0;i<m;i++)
        {
            char c;
            int x;
            cin>>x>>c;

                if(s[x]==s[1+n-x])
                    {
                        num--;
                        s[x]=c;
                        if(s[x]==s[n-x+1])num++;
                    }
                else
                    {
                        s[x]=c;
                        if(s[x]==s[n-x+1])num++;
                    }

            if(num==t)ans++;
        }
        printf("%d\n",ans);

    }
    return 0;


}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值