zoukankan      html  css  js  c++  java
  • 【LOJ #3095】【SNOI2019】—字符串(模拟)

    传送门

    考虑比较i,ji,j两个位置的时候其实是找a[i]&a[i+1],a[i+1]&a[i+2]a[i]&a[i+1],a[i+1]&a[i+2]第一个不同的地方

    所以每一段比较出来相同的位置的答案是一样的
    随便乱做一下就完了

    复杂度O(n)O(n)

    #include<bits/stdc++.h>
    using namespace std;
    const int RLEN=1<<20|1;
    inline char gc(){
        static char ibuf[RLEN],*ib,*ob;
        (ob==ib)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
        return (ob==ib)?EOF:*ib++;
    }
    #define gc getchar
    inline int read(){
        char ch=gc();
        int res=0,f=1;
        while(!isdigit(ch))f^=ch=='-',ch=gc();
        while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
        return f?res:-res;
    }
    #define ll long long
    #define re register
    #define pii pair<int,int>
    #define fi first
    #define se second
    #define pb push_back
    #define cs const
    #define bg begin
    #define poly vector<int>  
    #define chemx(a,b) ((a)<(b)?(a)=(b):0)
    #define chemn(a,b) ((a)>(b)?(a)=(b):0)
    cs int N=1000005;
    int n,p[N],ans[N],tot1,tot2;
    char s[N];
    int main(){
    	n=read();
    	scanf("%s",s+1);tot2=n;
    	for(int i=1;i<=n;i++){
    		if(s[i]>s[i+1])p[i]=1;
    		else if(s[i]<s[i+1])p[i]=-1;
    	}
    	for(int i=1,pos=1;i<=n;i=pos+1,pos=i){
    		while(!p[pos]&&pos<=n)pos++;
    		if(pos>n){for(;i<=n;i++)ans[++tot1]=i;break;}
    		if(p[pos]==-1)for(int j=pos;j>=i;j--)ans[tot2--]=j;
    		else for(int j=i;j<=pos;j++)ans[++tot1]=j;
    	}
    	for(int i=1;i<=n;i++)cout<<ans[i]<<" ";
    }
    
  • 相关阅读:
    javascript 学习笔记
    vim折叠设置(转载)
    描述符
    python运算符优先级
    python repr()和str()
    python super()
    [深入Python]__new__和__init__
    python中,类方法和静态方法区别。
    python中 os._exit() 和 sys.exit(), exit(0)和exit(1) 的用法和区别
    关于字符集和字符编码自己汇总记录
  • 原文地址:https://www.cnblogs.com/stargazer-cyk/p/12328485.html
Copyright © 2011-2022 走看看