#include <bits/stdc++.h> using namespace std; const int MAXN = 5e5+7; int pref[MAXN]; map<int, int> wyniki; int main(){ int n, x, masa, masa_popr; vector<int> tab; vector<int> sorted; cin >> n; tab.push_back(0); sorted.push_back(0); for(int i = 1; i <= n; i++){ cin >> x; tab.push_back(x); sorted.push_back(x); } sort(sorted.begin(), sorted.end()); //for(auto x: sorted){ // cout << x << " "; //} //cout << "\n0 "; pref[0] = 0; for(int i = 1; i <= n; i++){ pref[i] = pref[i-1] + sorted[i]; //cout << pref[i] << " "; } //cout << "\n"; wyniki[sorted[1]] = -1; for(int i = 2; i <= n; i++){ vector<int>::iterator ind = lower_bound(sorted.begin(), sorted.end(), sorted[i]); masa = pref[(ind-sorted.begin())]; //cout << "ryba = " << sorted[i] << " masa " << masa << "\n"; masa_popr = 0; while(masa_popr != masa){ ind = lower_bound(sorted.begin(), sorted.end(), masa); //cout << (ind-sorted.begin()) << " " << pref[(ind-sorted.begin())] << "\n"; masa_popr = masa; masa = pref[(ind-sorted.begin())-1]; } //cout << "UPD ryba = " << sorted[i] << " masa " << masa << "\n"; if(masa > sorted[n]){ wyniki[sorted[i]] = 1; }else{ wyniki[sorted[i]] = -1; } } for(int i = 1; i <= n; i++){ if(wyniki[tab[i]] == -1){ cout << "N"; }else{ cout << "T"; } } 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 | #include <bits/stdc++.h> using namespace std; const int MAXN = 5e5+7; int pref[MAXN]; map<int, int> wyniki; int main(){ int n, x, masa, masa_popr; vector<int> tab; vector<int> sorted; cin >> n; tab.push_back(0); sorted.push_back(0); for(int i = 1; i <= n; i++){ cin >> x; tab.push_back(x); sorted.push_back(x); } sort(sorted.begin(), sorted.end()); //for(auto x: sorted){ // cout << x << " "; //} //cout << "\n0 "; pref[0] = 0; for(int i = 1; i <= n; i++){ pref[i] = pref[i-1] + sorted[i]; //cout << pref[i] << " "; } //cout << "\n"; wyniki[sorted[1]] = -1; for(int i = 2; i <= n; i++){ vector<int>::iterator ind = lower_bound(sorted.begin(), sorted.end(), sorted[i]); masa = pref[(ind-sorted.begin())]; //cout << "ryba = " << sorted[i] << " masa " << masa << "\n"; masa_popr = 0; while(masa_popr != masa){ ind = lower_bound(sorted.begin(), sorted.end(), masa); //cout << (ind-sorted.begin()) << " " << pref[(ind-sorted.begin())] << "\n"; masa_popr = masa; masa = pref[(ind-sorted.begin())-1]; } //cout << "UPD ryba = " << sorted[i] << " masa " << masa << "\n"; if(masa > sorted[n]){ wyniki[sorted[i]] = 1; }else{ wyniki[sorted[i]] = -1; } } for(int i = 1; i <= n; i++){ if(wyniki[tab[i]] == -1){ cout << "N"; }else{ cout << "T"; } } return 0; } |