Codeforces Round #316 (Div. 2)-C. Replacement

也是醉了。。。大水题一枚,一开始看错题,白敲了大半个小时。。最后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;
	
	
} 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值