• 模拟+分类大讨论——cf


     显然,三元组前两位确定后,第三位最多只有两种情况

    答案只有111,112,121,211,122,212,221,123,132,213,231,312,321

    分别讨论下存不存在就行

    感觉题解的讨论方法不错,自己的写了(复制了)两百多行。。

    #include <bits/stdc++.h>
    #define F(i,a,b) for ( int i = (int)(a); i < (int)(b); ++i )
    #define ff first
    #define ss second
    using namespace std;
    using ii = pair<int,int>;
    using vi = vector<int>;
    
    const int INF = 1e9+7;
    
    int main() {
        ios::sync_with_stdio(0);
        int    n;
        cin >> n;
        vi a(n);
        F(i,0,n)
            cin >> a[i];
    
        set<int> res, active;
        multiset<int> L, R;
        map<int,int> leftmost, rightmost;
        F(i,0,n) {
            int x = a[i];
            R.insert(x);
            if (!leftmost.count(x))
                leftmost[x] = i;
            rightmost[x] = i;
        }
        F(i,0,n) {
            int x = a[i];
            R.erase(R.find(x));
            if (leftmost[x] == i)
                active.insert(x);
            if (rightmost[x] == i)
                active.erase(x);
            if (active.size() && *active.begin() < x)
                res.insert(121);
            if (active.size() && *active.rbegin() > x)
                res.insert(212);
            
            bool onLeft = L.find(x) != L.end();
            bool onRight = R.find(x) != R.end();
            auto Lmin  = L.size() ? *L.begin() : 0;
            auto Lless = L.lower_bound(x) == L.begin() ? 0 : *--L.lower_bound(x);
            auto Lmore = L.upper_bound(x) == L.end() ? 0 : *L.upper_bound(x);
            auto Lmax  = L.size() ? *L.rbegin() : 0;
            auto Rmin  = R.size() ? *R.begin() : 0;
            auto Rless = R.lower_bound(x) == R.begin() ? 0 : *--R.lower_bound(x);
            auto Rmore = R.upper_bound(x) == R.end() ? 0 : *R.upper_bound(x);
            auto Rmax  = R.size() ? *R.rbegin() : 0;
            
            if (onLeft && onRight)
                res.insert(111);
            if (onLeft && Rmax && Rmax > x)
                res.insert(112);
            if (Lmin && Lmin < x && onRight)
                res.insert(122);
            if (Lmax && Lmax > x && onRight)
                res.insert(211);
            if (Rmin && Rmin < x && onLeft)
                res.insert(221);
            if (Lmin && Rmax && Lmin < x && Rmax > x)
                res.insert(123);
    
            if (Lmin && Rless && Lmin < Rless && Rless < x)
                res.insert(132);
            if (Lmore && Rmax && Lmore > x && Lmore < Rmax)
                res.insert(213);
            if (Lless && Rmin && Lless < x && Lless > Rmin)
                res.insert(231);
            if (Lmax && Rmore && Lmax > Rmore && Rmore > x)
                res.insert(312);
            if (Lmax && Rless && Lmax > x && x > Rless)
                res.insert(321);
            L.insert(x);
        }
        for (auto t : res) {
            cout << t << endl;
        }
        return 0;
    }
  • 相关阅读:
    安装部署NetBeans mysql Tomact joget workflow 环境
    Django-分页扩展
    supervisor linux下进程管理工具
    注意python函数参数的可变变量的传递
    Python远程部署利器Fabric详解
    chrom 扩展程序安装
    supervisor
    python进度条
    os sys区别
    知乎上关于网站 权限系统的回答
  • 原文地址:https://www.cnblogs.com/zsben991126/p/12916145.html
Copyright © 2020-2023  润新知