跳到正文

题解

题解 P1823 【音乐会的等待】

越学越掂约 2 分钟
原文
文章信息与版本

文章信息

发布
2018年4月27日
收录
2026年7月1日
更新
2026年11月16日
篇幅
约 2 分钟
获赞
6
题目
P1823

版本

  1. v1当前

这道题……

怎么说呢,跟P4333很像,而且那题的数据比这题要强

P4333的链接

我的题解

贴代码

C++
#include<iostream>
using namespace std;
long long st[10000000],n,top=1,ans,m;
int main()
{
    cin>>n;
    int a;
    cin>>st[1];
    for(int i=2;i<=n;i++)
    {
        cin>>a;
        if(st[top]>a)
        {
            top++,ans++,st[top]=a;
        }
        else
        {
            int l=1,r=top;
            while(l<r)
            {
                m=(l+r)>>1;
                if(r==l+1)m=r;
                if(a>=st[m])r=m-1;
                else l=m;
            }
            ans+=top-l+1;
            while(top>0&&st[top]<a)top--;
            st[++top]=a;
        }
    }
    cout<<ans;
}
原文
存档评论1 条抓取于