I solved the problem and then I got time_lim, I need to optimize this algorithm so that it passes 2 tests, not enough 4-5 ms. The algorithm searches for the first occurrence of an element that is not greater than the i-th and its index is greater than i, if it does not output -1.
int i(0),j(0); int n1; v_t v; //вектор типа int auto it(v.begin()); bool perd(int n) { ++j; if(n1>n) { cout<<j<<' '; return true; } return false; } void fun(int n) { ++i; n1=n; it=find_if(v.begin()+i,v.end(),perd); if(it==v.end()) cout<<-1<<' '; j=i; } void funcin(int &n) { cin>>n; } int main() { cin >> n1; v.resize(n1); for_each(v.begin(),v.end(),funcin); for_each(v.begin(),v.end(),fun); return 0; } Full text of the problem:
Lineland is a one-dimensional world, which is a straight line, on which are located N cities, sequentially numbered from 0 to N - 1. The direction away from the first city to zero is called western, and in the opposite direction - eastern.
When the crisis suddenly began in Linelandia, everyone in the world began to experience deep confusion. Rumors circulated throughout Linelandia that they lived better in the east than in the west. Thus began the Great Lineland Relocation. The inhabitants of the world went to the east by whole cities, having left their native streets, and moved until they came to a city in which the average price of living was less than in their own.