zoukankan      html  css  js  c++  java
  • Codeforces Codeforces Round #316 (Div. 2) C. Replacement SET

    C. Replacement
    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/570/problem/C

    Description

    Daniel has a string s, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of replacementas the following sequence of steps: find a substring ".." (two consecutive periods) in string s, of all occurrences of the substring let's choose the first one, and replace this substring with string ".". In other words, during the replacement operation, the first two consecutive periods are replaced by one. If string s contains no two consecutive periods, then nothing happens.

    Let's define f(s) as the minimum number of operations of replacement to perform, so that the string does not have any two consecutive periods left.

    You need to process m queries, the i-th results in that the character at position xi (1 ≤ xi ≤ n) of string s is assigned value ci. After each operation you have to calculate and output the value of f(s).

    Help Daniel to process all queries.

     
     

    Input

    The first line contains two integers n and m (1 ≤ n, m ≤ 300 000) the length of the string and the number of queries.

    The second line contains string s, consisting of n lowercase English letters and period signs.

    The following m lines contain the descriptions of queries. The i-th line contains integer xi and ci (1 ≤ xi ≤ nci — a lowercas English letter or a period sign), describing the query of assigning symbol ci to position xi.

    Output

    Print m numbers, one per line, the i-th of these numbers must be equal to the value of f(s) after performing the i-th assignment.

    Sample Input

    10 3
    .b..bz....
    1 h
    3 c
    9 f

    Sample Output

    4
    3
    1

    HINT

    题意

    给你一个字符串,然后每两个点可以变成一个点

    然后有m次修改操作,每次可以修改一个位置的字符

    然后问你修改之后,需要多少次操作,把所有的点,都变成连续的一个点

    题解

    我比较蠢,我用的set,太蠢了

    维护的是每一个pos的左边的字母和右边的字母位置

    正解不超过30行,几个if就好了……

    代码:

    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef int ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define test freopen("test.txt","r",stdin)
    #define maxn 500000
    #define mod 1000000007
    #define eps 1e-9
    const int inf=0x3f3f3f3f;
    const ll infll = 0x3f3f3f3f3f3f3f3fLL;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //**************************************************************************************
    
    set<ll> S;
    ll CC(ll num)
    {
        return max(num-1LL,0LL);
    }
    ll vis[maxn];
    char s[maxn];
    char c;
    ll x;
    int main()
    {
        ll n=read();
        ll m=read();
        scanf("%s",s+1);
        ll ans=0;
        ll tmp=0;
        S.insert(0);S.insert(n+1);
        int len = strlen(s+1);
        for(int i=1;i<=len;i++)
        {
            if(s[i]!='.')
            {
                ans+=CC(tmp);
                tmp=0;
                vis[i]=1;
                S.insert(i);
            }
            else
                tmp++;
        }
        ans+=CC(tmp);
    
        for(int i=0;i<m;i++)
        {
            x=read();
    
            scanf("%c",&c);
            if(c!='.')
            {
                if(vis[x])
                    printf("%d
    ",ans);
                else
                {
                    vis[x]=1;
                    ll c=*S.lower_bound(x);
                    ll d=*--S.lower_bound(x);
                    ans=ans-CC(c-d-1)+CC(x-d-1)+CC(c-x-1);
                    S.insert(x);
                    printf("%d
    ",ans);
                }
            }
            else
            {
                if(!vis[x])
                    printf("%d
    ",ans);
                else
                {
                    vis[x]=0;
                    ll c=*S.lower_bound(x);
                    S.erase(c);
                    c=*S.lower_bound(x);
                    ll d=*--S.lower_bound(x);
                    ans=ans+CC(c-d-1)-CC(x-d-1)-CC(c-x-1);
                    printf("%d
    ",ans);
                }
            }
        }
    }
  • 相关阅读:
    MSSQL_打开xp_cmdshell
    想在win7 32bit的情况下装个64位虚拟机的想法
    查看系统已运行了多久
    sql弄个表结构出来..
    在win下的cmd 的find
    告别google.com.hk的龟速
    VC常用数据类型使用转换详解
    C++中的文件输入/输出ios:xx eat Processing(zz)
    X86汇编语言学习手记(1)
    程序员数据结构笔记
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4728871.html
Copyright © 2011-2022 走看看