10.4比赛记录

· · 个人记录

比赛复盘

T1: 数学,求 log

T2: 数学,一位一位枚举,如果不一样说明进后面的都是 1

T3: 是字典序,逐位确定,记录最后出现位置,用单调队列

T4: DP,—————————————————————————————————————————————————————

预计:

100 + 100 + 0 + 40 = $ ~~420~~ $240

实际:

100 + 100 + 0 + 20 = $ ~~220000~~ $220

不足

  1. 数学
  2. 数学,位运算
  3. STL$ ,贪心,单调队列或 $set
  4. 玄学

    题解

    ( t1 , t2 不讲 )

    t3

    因为是字典序,所以可以存下每个数字最后出现的位置,然后一位一位枚举,在合法的方案中取最大或最小

而最后一次出现的位置要用单调队列或 set 来存

代码如下:

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define itn long long
#define x first
#define fst ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define y second
const int N=1e6+5,INF=0x3f3f3f3f3f3f3f3f;
int l,r;
int n;
int a[N];
int t[N];
bool vis[N];
int ende[N];
int s;
priority_queue<int,vector<int>,greater<int>>pq;
signed main(){
    freopen("subsequence.in","r",stdin);
    freopen("subsequence.out","w",stdout);
    int n;
    cin>>n;
    int ans1=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        t[a[i]]++;
        ende[a[i]]=max(ende[a[i]],i);
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        if(t[i])
        {
            pq.push(ende[i]);
            ans++;
        }
    }
    cout<<ans<<endl;
    short t=1;
    int x=0;
    for(int i=1;i<=ans;i++)
    {
        t*=-1;
        int zhazha=INF,la=x+1;
        for(int j=x+1;j<=pq.top();j++)
        {
            if(a[j]*t<zhazha&&!vis[a[j]])
            {
                zhazha=a[j]*t;
                la=j;
            }
        }
        x=la;
        cout<<a[x]<<" ";
        vis[a[x]]=1;
        while(!pq.empty()&&vis[a[pq.top()]])
        {
            pq.pop();
        }
    }
    cout<<endl;
    return 0;
}

t4

略