#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; #define st first #define nd second typedef pair<int,int> pun; typedef long long ll; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; map<int, vector<int>> maps; vector<int> v; for (int i = 0; i < n; i ++) { int x; cin >> x; v.push_back(x); maps[x].push_back(i); } sort(v.begin(), v.end()); v.resize(unique(v.begin(), v.end()) - v.begin()); vector<ll> pref; pref.push_back(0); for (int i = 0; i < v.size(); i ++) { pref.push_back(pref.back() + v[i] * (ll)maps[v[i]].size()); } // for (ll x : pref) { // cerr << x << " "; // } // cerr <<"\n"; vector<bool> ans; ans.resize(n, true); int last = 0; // for (int i = 0; i < v.size(); i ++ ) { // cerr << v[i] << " "; // } // cerr << "\n"; for (int i = (int)v.size()-2; i >= 0; i--) { if (pref[i+1] <= v[i+1]) { last = i; break; } } for (int j = last; j >= 0; j --) { for (int idx : maps[v[j]]) { // cerr << idx << " "; ans[idx] = false; } } string res; for (bool x : ans) { res += (x ? "T" : "N"); } cout << res; }
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 | #include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; #define st first #define nd second typedef pair<int,int> pun; typedef long long ll; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; map<int, vector<int>> maps; vector<int> v; for (int i = 0; i < n; i ++) { int x; cin >> x; v.push_back(x); maps[x].push_back(i); } sort(v.begin(), v.end()); v.resize(unique(v.begin(), v.end()) - v.begin()); vector<ll> pref; pref.push_back(0); for (int i = 0; i < v.size(); i ++) { pref.push_back(pref.back() + v[i] * (ll)maps[v[i]].size()); } // for (ll x : pref) { // cerr << x << " "; // } // cerr <<"\n"; vector<bool> ans; ans.resize(n, true); int last = 0; // for (int i = 0; i < v.size(); i ++ ) { // cerr << v[i] << " "; // } // cerr << "\n"; for (int i = (int)v.size()-2; i >= 0; i--) { if (pref[i+1] <= v[i+1]) { last = i; break; } } for (int j = last; j >= 0; j --) { for (int idx : maps[v[j]]) { // cerr << idx << " "; ans[idx] = false; } } string res; for (bool x : ans) { res += (x ? "T" : "N"); } cout << res; } |