constructive algorithms sortings

Please click on ads to support us..

C++ Code:

#include "bits/stdc++.h"
using namespace std;

#define ll  			long long int
#define nl			    "\n"
#define yes 			cout << "YES\n"
#define no  			cout << "NO\n"
#define lower(s)        transform(s.begin(), s.end(), s.begin(), ::tolower);
#define upper(s)        transform(s.begin(), s.end(), s.begin(), ::toupper);
#define vin 			vector<int>
#define vln 			vector<ll>
#define pb  			push_back
#define all(x) 			(x).begin(), (x).end()
#define rall(x) 		(x).rbegin(), (x).rend()
#define FastIo 		    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)


const ll N = 1e6 + 1 ;
const ll MOD = 1e9 + 7 ;


int main()
{
        
        FastIo ;
        
        int t = 1 ;
        cin >> t ;
        while(t--){

            ll n, m, k, q ;
            cin >> n ;
            vin v(n), a;
            for(int i=0; i<n; i++){
                cin >> v[i];
            }
            

            vector<pair<int, int>> p(n), p2 ;
            
            for(int i=0; i<n; i++){
                p[i] = {v[i], i}; 
            }
            sort(all(p));
            vector<int> ans(n);
            int mx = n ;
            for(int i=0; i<n; i++){
                ans[p[i].second] = mx ;
                mx--;
            }
            for(auto u : ans){
                cout << u << ' ';
            }cout << endl;
            
            
        }

	return 0 ;
}



/*

check negative value then mx = -1e9
check ll and int

sieve----

    isPrime[0] = isPrime[1] = 1 ;
    for(int i=2; i<=N; i+=2){
        isPrime[i] = 1 ;
    }
    isPrime[2] = 0 ;
    for(int i=3; i*i<=N; i+=2){
        if(isPrime[i] == 0){
            for(int j=i*i; j<=N; j+=i){
                isPrime[j] = 1 ;
            }
        }   
    }

*/



Comments

Submit
0 Comments
More Questions

1257B - Magic Stick
18C - Stripe
1203B - Equal Rectangles
1536A - Omkar and Bad Story
1509A - Average Height
1506C - Double-ended Strings
340A - The Wall
377A - Maze
500A - New Year Transportation
908D - New Year and Arbitrary Arrangement
199A - Hexadecimal's theorem
519C - A and B and Team Training
631A - Interview
961B - Lecture Sleep
522A - Reposts
1166D - Cute Sequences
1176A - Divide it
1527A - And Then There Were K
1618E - Singers' Tour
1560B - Who's Opposite
182B - Vasya's Calendar
934A - A Compatible Pair
1618F - Reverse
1684C - Column Swapping
57C - Array
1713D - Tournament Countdown
33A - What is for dinner
810A - Straight A
1433C - Dominant Piranha
633A - Ebony and Ivory