zoukankan      html  css  js  c++  java
  • Codeforces 1178B. WOW Factor

    传送门

    显然对每个 $o$ ,考虑左边和右边分别有多少 $w$,那么这个 $o$ 的贡献就是左右 $w$ 的出现次数相乘

    $w$ 的出现次数可以直接根据每一段连续的 $v$ 得到

    那么从左到右扫一遍,动态维护一下左右两边的 $w$ ,遇到 $o$ 就计算一下贡献即可

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<cmath>
    using namespace std;
    typedef long long ll;
    inline int read()
    {
        int 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<<1)+(x<<3)+(ch^48); ch=getchar(); }
        return x*f;
    }
    const int N=2e6+7;
    int n,tl,tr;
    char s[N];
    ll ans;
    int main()
    {
        scanf("%s",s+1); n=strlen(s+1);
        int pre=n+1;
        for(int i=n;i>=1;i--)
            if(s[i]!='v') { if(pre!=i+1) tr+=pre-i-2; pre=i; }
        if(pre!=1) tr+=pre-2;
        pre=0;
        for(int i=1;i<=n;i++)
        {
            if(s[i]=='v') continue;
            if(pre!=i-1) tl+=i-pre-2,tr-=i-pre-2;
            ans+=1ll*tl*tr; pre=i;
        }
        printf("%lld
    ",ans);
        return 0;
    }
  • 相关阅读:
    《将博客搬至CSDN》
    2015-05-01 至 2015-07-30错误总结
    2015-01-01至2015-04-30错误积累
    2015-07-30 至 2016-03-16错误Note
    2014-11-21错误总结
    Spring 和 SpringMVC 的区别
    spring 容器加载
    Spring注解
    自定义拦截器
    Js闭包
  • 原文地址:https://www.cnblogs.com/LLTYYC/p/11606959.html
Copyright © 2011-2022 走看看