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);
                }
            }
        }
    }
  • 相关阅读:
    这可能是全网最全的流媒体知识科普文章
    JavaCV实战专栏文章目录(JavaCV速查手册)
    JavaCV复杂滤镜filter特效处理入门教程和常用案例汇总
    【PC桌面软件的末日,手机移动端App称王】写在windows11支持安卓,macOS支持ios,龙芯支持x86和arm指令翻译
    如何在龙芯架构和国产化操作系统平台上运行javacv
    如何在国产龙芯架构平台上运行c/c++、java、nodejs等编程语言
    JavaCV开发详解之35:使用filter滤镜实现画中画,以屏幕画面叠加摄像头画面为例
    JavaCV开发详解之34:使用filter滤镜实现字符滚动和无限循环滚动字符叠加,跑马灯特效制作
    JavaCV开发详解之33:使用filter滤镜实现动态日期时间叠加
    JavaCV开发详解之32:使用filter滤镜实现中文字符叠加
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4728871.html
Copyright © 2011-2022 走看看