简单模拟,每连续的'..'合并成'.'
代码如下:
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
typedef long long ll;
const ll N = 3e5+10;
ll n, m, x, cnt;
char a[N], c;
int main()
{
scanf("%I64d%I64d", &n, &m);
scanf("%s", a);
cnt = 0;
for(int j = 0; j < n; j++)
{
if(a[j] == '.' && a[j+1] == '.')
{
cnt ++;
}
}
for(int i = 1; i <= m; i++)
{
scanf("%I64d %c", &x, &c);
x--;
if(a[x] != '.' && c == '.')
{
if(a[x-1] == '.') cnt++;
if(a[x+1] == '.') cnt++;
}
else if(a[x] == '.' && c != '.')
{
if(a[x-1] == '.') cnt--;
if(a[x+1] == '.') cnt--;
}
a[x] = c;
printf("%I64d\n", cnt);
}
return 0;
}