也是醉了。。。大水题一枚,一开始看错题,白敲了大半个小时。。最后5分钟敲了一份代码在结束前交上去。。。。wa test3
之后一看后台.....加个if判断就 ac。。。
题意:给一字符串, 遇到两个连续的点 【..】 计数器+1,并变成一个点,把这样的操作叫做f(x)
m次查询
每次给 X,C ---->把源字符串的x位置替换为字符c
并计算一下当前字符串 要进行多少次f(x)操作 才能完全没有连续的2个点【.】
第一次for一下记录 源字符串要的f(x)数
对每次查询
1 :如果输入的替换字符是【.】,如果位置x已经为【.】,不操作,否则把位置x填为【.】;
2 :如果不是【.】,如果位置x原来是【.】,则判断x左右,如果左右都是【.】,计算器-2,若只有一个就减一,一个都没则不操作
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;
const __int64 maxn = 100005;
char tm[300005];
set<int> q;
set<int>::iterator it,NEXT,sb;
int main()
{
char c;
int n,m,i,x;
scanf("%d%d",&n,&m);
getchar();
for (i=1;i<=n;i++)
{
scanf("%c",&tm[i]);
if (tm[i]=='.')
{
q.insert(i);
}
}
getchar();
int cun=0;
for (i=1;i<=n;i++)
{
if (tm[i]=='.'&& tm[i+1]=='.')
cun++;
}
// printf("%d\n",cun);
int k;
for (k=1;k<=m;k++)
{
scanf("%d %c",&x,&c);
getchar();
if (c=='.')
{
if (tm[x]!='.')
{
if ( q.count(x+1)&& q.count(x-1))
cun+=2;
else
if ( q.count(x+1)|| q.count(x-1))
cun++;
q.insert(x);
}
}
else
{
if (q.count(x))
{
if ( q.count(x+1)&& q.count(x-1))
cun-=2;
else
if ( q.count(x+1)|| q.count(x-1))
cun--;
q.erase(x);
}
}
tm[x]=c;
printf("%d\n",cun);
}
return 0;
}