#include <bits/stdc++.h> #define dbg(x) " [" << #x << ": " << (x) << "] " using namespace std; template<typename A,typename B> ostream& operator<<(ostream& out,const pair<A,B>& p) { return out << "(" << p.first << ", " << p.second << ")"; } template<typename T> ostream& operator<<(ostream& out,const vector<T>& c) { out << "{"; for(auto it = c.begin(); it != c.end(); it++) { if(it != c.begin()) out << ", "; out << *it; } return out << "}"; } void solve() { int n; cin >> n; vector<pair<long long,int>> v(n); for(int i = 0; i < n; i++) { cin >> v[i].first; v[i].second = i; } if(n == 1) { cout << 'T' << endl; return; } sort(v.begin(),v.end()); vector<long long> s(n); vector<int> id(n); s[0] = v[0].first; int l = -1; id[0] = l; vector<int> ls(n); ls[0] = 0; for(int i = 1; i < n; i++) { s[i] = s[i - 1] + v[i].first; while(l + 1 < n && v[l + 1].first < s[i]) { l++; } id[i] = l; ls[i] = ls[i - 1]; if(v[i].first > v[i - 1].first) { ls[i] = 1; } } vector<int> ans(n); for(int i = n - 1; i >= 0; i--) { int x = 0; if(ls[i]) { if(id[i] == n - 1) { x = 1; } else if(!(id[i] == -1)) { x = ans[v[id[i]].second]; } } ans[v[i].second] = x; } for(int i = 0; i < n; i++) { cout << (ans[i] ? 'T' : 'N'); } cout << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int testNum = 1; //cin >> testNum; for(int i = 1; i <= testNum; i++) { solve(); } return 0; }
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 67 68 69 70 71 72 73 74 75 | #include <bits/stdc++.h> #define dbg(x) " [" << #x << ": " << (x) << "] " using namespace std; template<typename A,typename B> ostream& operator<<(ostream& out,const pair<A,B>& p) { return out << "(" << p.first << ", " << p.second << ")"; } template<typename T> ostream& operator<<(ostream& out,const vector<T>& c) { out << "{"; for(auto it = c.begin(); it != c.end(); it++) { if(it != c.begin()) out << ", "; out << *it; } return out << "}"; } void solve() { int n; cin >> n; vector<pair<long long,int>> v(n); for(int i = 0; i < n; i++) { cin >> v[i].first; v[i].second = i; } if(n == 1) { cout << 'T' << endl; return; } sort(v.begin(),v.end()); vector<long long> s(n); vector<int> id(n); s[0] = v[0].first; int l = -1; id[0] = l; vector<int> ls(n); ls[0] = 0; for(int i = 1; i < n; i++) { s[i] = s[i - 1] + v[i].first; while(l + 1 < n && v[l + 1].first < s[i]) { l++; } id[i] = l; ls[i] = ls[i - 1]; if(v[i].first > v[i - 1].first) { ls[i] = 1; } } vector<int> ans(n); for(int i = n - 1; i >= 0; i--) { int x = 0; if(ls[i]) { if(id[i] == n - 1) { x = 1; } else if(!(id[i] == -1)) { x = ans[v[id[i]].second]; } } ans[v[i].second] = x; } for(int i = 0; i < n; i++) { cout << (ans[i] ? 'T' : 'N'); } cout << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int testNum = 1; //cin >> testNum; for(int i = 1; i <= testNum; i++) { solve(); } return 0; } |