就算是链表 写爆就没问题了吧
查看原帖
就算是链表 写爆就没问题了吧
160663
一中益达楼主2020/6/11 21:39

两份代码一个思路..第一个带log开O2过了

想改成第二个的链表形式就爆了。。WA30分

救救孩子吧

#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
char s[1290382];
struct node
{
    int cnt,sum;
    bool operator<(const node &x)const
    {
        if(x.sum==sum) return x.cnt<cnt;
        return x.sum>sum;
    }
};
priority_queue<node> q;
int n;
int minn=0;
int maxx=0;
char organ;
int sumx;
int main()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    q.push(node{n,0});
    organ=s[n-1];
    sumx=0;
    for(int i=n-1;i>=1;i--)
    {
        if(s[i+1]==organ) q.push((node){i,sumx});
        if(s[i+1]>organ)
        {
            q.push((node){i,--minn});
            sumx=minn;
        }
        if(s[i+1]<organ)
        {
            q.push((node){i,++maxx});
            sumx=maxx;
        }
        organ=s[i-1];
    }
    while(!q.empty())
    {
        printf("%d ",q.top().cnt);
        q.pop();
    }
    return 0;
}

#include<cstdio>
#include<algorithm>
using namespace std;
char s[1290382];
int bitch[1000050];
int fan[1000050];
char organ;
int head;
int tail;
int n;
int main()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    head=tail=n;
    organ=s[n-1];
    for(int i=n-1;i>=1;i--)
    {
        if(s[i+1]==organ)
        {
            if(head==i+1)
            {
                bitch[i]=head;
                fan[head]=i;
                head=i;
            }
            else
            {
                bitch[fan[tail]]=i;
                fan[i]=fan[tail];
                bitch[i]=tail;
                fan[tail]=i;
            }
        }
        if(s[i+1]>organ)
        {
            bitch[tail]=i;
            fan[i]=tail;
            tail=i;
        }
        if(s[i+1]<organ)
        {
            bitch[i]=head;
            fan[head]=i;
            head=i;
        }
        organ=s[i-1];
    }
    while(head!=tail)
    {
        printf("%d ",head);
        head=bitch[head];
    }
    printf("%d",tail);
    return 0;
}
2020/6/11 21:39
加载中...