#include <bits/stdc++.h> #define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define debug(x) cerr << #x << " " << x << endl #define int long long #define st first #define nd second using namespace std; const int N(5e5 + 13); const int MAX(LLONG_MAX); int n; int arr[N]; int sum_lesser, tmp; bool flag; string s; map <int, pair<int, int> > weights; map <int, bool> res; int32_t main() { boost; cin >> n; for (int i = 1; i <= n; i++) { cin >> arr[i]; weights[arr[i]].st++; } for (auto& it : weights) { it.nd.nd = sum_lesser; sum_lesser += it.st * it.nd.st; } auto last = weights.rbegin(); if (last->nd.st == 1 || last->nd.nd > 0) { res[last->st] = true; } for (auto it = weights.rbegin(); it != weights.rend(); it++) { if(it == weights.rbegin()){ continue; } tmp = it->nd.nd; if (tmp != 0) { tmp += it->st * it->nd.st; } auto larger = prev(it); if (tmp > larger->st) { res[it->st] = res[larger->st]; } } for (int i = 1; i <= n; i++) { res[arr[i]] ? cout << "T" : cout << "N"; } cout << endl; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #include <bits/stdc++.h> #define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define debug(x) cerr << #x << " " << x << endl #define int long long #define st first #define nd second using namespace std; const int N(5e5 + 13); const int MAX(LLONG_MAX); int n; int arr[N]; int sum_lesser, tmp; bool flag; string s; map <int, pair<int, int> > weights; map <int, bool> res; int32_t main() { boost; cin >> n; for (int i = 1; i <= n; i++) { cin >> arr[i]; weights[arr[i]].st++; } for (auto& it : weights) { it.nd.nd = sum_lesser; sum_lesser += it.st * it.nd.st; } auto last = weights.rbegin(); if (last->nd.st == 1 || last->nd.nd > 0) { res[last->st] = true; } for (auto it = weights.rbegin(); it != weights.rend(); it++) { if(it == weights.rbegin()){ continue; } tmp = it->nd.nd; if (tmp != 0) { tmp += it->st * it->nd.st; } auto larger = prev(it); if (tmp > larger->st) { res[it->st] = res[larger->st]; } } for (int i = 1; i <= n; i++) { res[arr[i]] ? cout << "T" : cout << "N"; } cout << endl; } |