mycode

#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;

const int N = 5e5+10;

struct BIT{
    int c[N];
    void add(int x,int p){}
};

int n;
int a[N];
map<int,vector<int>> mp; 
vector<pair<int,int>> p;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        mp[a[i]].pb(i);
    }
    for(auto i : mp){
        vector<int> v;
        for(auto j : i.se){
            v.pb(j);
        }
        int l=0,r=v.size()-1;
        while(l<r){
            p.pb({v[l],v[r]});
            l++,r--;
        }
    }
    
    sort(p.begin(),p.end(),[](const pair<int,int> x,const pair<int,int> y){
        return x.fi==y.fi ? x.se>y.se : x.fi<y.fi; 
    });



    return 0;
}
posted @ 2026-09-10 10:11  词印  阅读(8)  评论(0)    收藏  举报