zoukankan      html  css  js  c++  java
  • Good Triple CodeForces

    大意: 给定01字符串, 求有多少个区间$[l,r]$, 使得存在正整数$x,k$满足$1le x,kle n,lle x<x+2kle r,s_x=s_{x+k}=s_{x+2k}$.

    0和1分开考虑, 那么问题就转化为给定排列求有多少个区间包含等差子序列, 可以用CF 452F Permutation的方法求出最小等差子序列位置, 然后就很容易能统计出答案.

    复杂度是$O(n)$的

    #include <iostream>
    #include <sstream>
    #include <algorithm>
    #include <cstdio>
    #include <math.h>
    #include <set>
    #include <map>
    #include <queue>
    #include <string>
    #include <string.h>
    #include <bitset>
    #define REP(i,a,n) for(int i=a;i<=n;++i)
    #define PER(i,a,n) for(int i=n;i>=a;--i)
    #define hr putchar(10)
    #define pb push_back
    #define lc (o<<1)
    #define rc (lc|1)
    #define mid ((l+r)>>1)
    #define ls lc,l,mid
    #define rs rc,mid+1,r
    #define x first
    #define y second
    #define io std::ios::sync_with_stdio(false)
    #define endl '
    '
    #define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> pii;
    const int P = 1e9+7, P2 = 998244353, INF = 0x3f3f3f3f;
    ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
    ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
    ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
    inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
    //head
    
    
    const int N = 1e6+10;
    int n, f[N];
    char s[N];
    vector<int> g[2];
    
    int main() {
    	scanf("%s", s+1);
    	n = strlen(s+1);
    	REP(i,1,n) g[s[i]-'0'].pb(i);
    	REP(i,0,1) if (g[i].size()>=3) {
    		int sz = g[i].size();
    		REP(j,1,sz-2) {
    			for (int k=j+1; k<min(sz,j+5); ++k) {
    				int r = 2*g[i][k]-g[i][j], l = 2*g[i][j]-g[i][k];
    				if (1<=r&&r<=n&&s[r]==s[g[i][j]]) { 
    					f[r] = max(f[r], g[i][j]);
    				}
    				if (1<=l&&l<=n&&s[l]==s[g[i][j]]) {
    					f[g[i][k]] = max(f[g[i][k]], l);
    				}
    			}
    		}
    	}
    	REP(i,1,n) f[i] = max(f[i-1], f[i]);
    	ll ans = 0;
    	REP(i,1,n) ans += f[i];
    	printf("%lld
    ", ans);
    }
    
  • 相关阅读:
    Array.sort源码
    Linkedlist源码
    最大公约数 2.7
    腾讯笔试题
    腾讯2014校园招聘笔试题
    指针问题
    JavaScript 日历
    QT 初阶 第二章 创建对话框(查找对话框实例)
    QT 初阶 1.3 节 控件的几何排列
    “项目中的问题”
  • 原文地址:https://www.cnblogs.com/uid001/p/10941847.html
Copyright © 2011-2022 走看看