CF1454F Array Partition

感觉这种题不就这么几种可能的后续发展吗。

还没调试完的代码:

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for (int i=1;i<=n;i++)
#define REP(i,a,b) for (int i=a;i<=b;i++)
 
#define pb push_back
#define fi first
#define se second
#define pi pair<int,int>
#define mp make_pair
 
typedef long long ll;
typedef complex<double> comp;
 
const int inf=0x3f3f3f3f;
const ll linf=1e18;
const int N=5e5+10;
const double eps=1e-10;
const ll mo=1e9+7;

int t;
int n;
int a[N];
int l,r;
int u,w;
multiset<int> m;
void del(int x) {
    auto it=m.find(x);
    if (it!=m.end()) {
        m.erase(it);
    }
}
int main() {
 
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    cin>>t;
    while (t--) {
        cin>>n;
        FOR(i,n) cin>>a[i];
        m.clear();
        FOR(i,n) m.insert(a[i]);
        l=1,r=n;
        u=a[1],w=a[n];
        del(u);del(w);
        bool ok=0;
        while (l<r-1) {
            u=max(u,a[l]),w=max(w,a[r]);
        	//cout<<l<<" "<<r<<" "<<u<<" "<<w<<endl;
            if (u==w) {
                int q=*m.begin();
                if (q==w) {
                    ok=1;
                    cout<<"YES"<<endl;
                    cout<<l<<" "<<r-l-1<<" "<<n-r+1<<endl;
                    break;
                } else {
                    if (a[l+1]<a[r-1]) {
                        del(a[++l]);
                    } else {
                        del(a[--r]);
                    }
                }
            } else if (u<w) {
                del(a[++l]);
            } else {
                del(a[--r]);
            }
        }
        if (!ok) cout<<"NO"<<endl;
    }
    return 0;
}

  

posted @ 2021-03-07 20:42  AngelKnows  阅读(61)  评论(0)    收藏  举报