#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n, tab[500010];
LL lab[500010], wyn, wynik[500010];
bool funkcja2(LL a){
LL x=lab[a];
for (LL i=a+1; i<n; i++){
if (x+tab[i-1]>tab[i]){
x=lab[i];
}else{
return false;
}
}
return true;
}
LL binsearch (){
LL pol, p=0, q=n-1;
while (p<=q){
pol=(p+q)/2;
bool y=funkcja2(pol);
if (y!=true){
p=pol+1;
}else if (y==true){
q=pol-1;
}
}
return p;
}
void funkcja(){
lab[0]=0;
LL pow=1;
for (LL i=1; i<n; i++){
if (tab[i]==tab[i-1]){
//lab[tab[i].second]=lab[tab[i-1].second];
pow++;
lab[i]=lab[i-1];
}else{
lab[i]=(tab[i-1]*pow)+lab[i-1];
pow=1;
}
}
// for (int i=0; i<n; i++){
// cout<<tab[i]<<" ";
// }cout<<'\n';
// for (int i=0; i<n; i++){
// cout<<lab[i]<<" ";
// }cout<<'\n';
}
int main (){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
for (LL i=0; i<n; i++){
cin>>tab[i];
wynik[i]=tab[i];
}
sort (tab, tab+n);
if (tab[n-1]==tab[0]){
for (LL i=0; i<n; i++){
cout<<"N";
}
return 0;
}
funkcja();
wyn=tab[binsearch()];
//cout<<'\n'<<wyn<<'\n';
for (LL i=0; i<n; i++){
if (wynik[i]<wyn){
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | #include <bits/stdc++.h> using namespace std; typedef long long LL; LL n, tab[500010]; LL lab[500010], wyn, wynik[500010]; bool funkcja2(LL a){ LL x=lab[a]; for (LL i=a+1; i<n; i++){ if (x+tab[i-1]>tab[i]){ x=lab[i]; }else{ return false; } } return true; } LL binsearch (){ LL pol, p=0, q=n-1; while (p<=q){ pol=(p+q)/2; bool y=funkcja2(pol); if (y!=true){ p=pol+1; }else if (y==true){ q=pol-1; } } return p; } void funkcja(){ lab[0]=0; LL pow=1; for (LL i=1; i<n; i++){ if (tab[i]==tab[i-1]){ //lab[tab[i].second]=lab[tab[i-1].second]; pow++; lab[i]=lab[i-1]; }else{ lab[i]=(tab[i-1]*pow)+lab[i-1]; pow=1; } } // for (int i=0; i<n; i++){ // cout<<tab[i]<<" "; // }cout<<'\n'; // for (int i=0; i<n; i++){ // cout<<lab[i]<<" "; // }cout<<'\n'; } int main (){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n; for (LL i=0; i<n; i++){ cin>>tab[i]; wynik[i]=tab[i]; } sort (tab, tab+n); if (tab[n-1]==tab[0]){ for (LL i=0; i<n; i++){ cout<<"N"; } return 0; } funkcja(); wyn=tab[binsearch()]; //cout<<'\n'<<wyn<<'\n'; for (LL i=0; i<n; i++){ if (wynik[i]<wyn){ cout<<"N"; }else{ cout<<"T"; } } return 0; } |
English