Submission #764666

#TimeUsernameProblemLanguageResultExecution timeMemory
764666lollipopStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
538 ms63732 KiB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define int long long
#define pb push_back
#define s second
#define f first
#define pf push_front
#define inf 100000000000000000
#define bitebi __builtin_popcountll
#define FOR( i , n ) for( int i = 0 ; i < n ; i ++ )
#define YES cout <<"YES\n"
#define NO cout << "NO\n"
#define debug cout << "Here Fine" << endl ;
#define pr pair < int , int >
#define fbo find_by_order // returns iterator
#define ook order_of_key // returns strictly less numbers than key
using namespace std ;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const double Pi=acos(-1.0);
const double EPS=1E-8;
const int mod =  1000000007 ;
const int mod1 = 998244353 ;
const int N = 2e5 + 10 ;
mt19937 R(time(0));
map < int , int > ma , ma1 ;
vector < int > v[ N ] ; 
void solve(){
     int n ; cin >> n ;
     int a[ n ] ; 
     set < int > se ; 
     FOR( i , n ){
     	cin >> a[ i ] ;
     	se.insert( a[ i ] ) ; 
	 }
     int cnt = 1 ;
     for( auto x : se ){
     	ma[ x ] = cnt ;
     	ma1[ cnt ] = x ; 
     	cnt ++ ; 
	 }
	 FOR( i , n ) a[ i ] = ma[ a[ i ] ] ; 
	 set < pair < int , int > > ps ; 
	 FOR( i , n ){
	 	int x = a[ i ] ;
	 	if( v[ x ].size() == 0 ){
	 	   v[ x ].pb( i ) ; 
	 	   ps.insert( { i , x } ) ; 
		   continue ; 	
		}
		int ls = v[ x ][ v[ x ].size() - 1 ] ; 
		while( true ){
			if( ps.size() == 0 ) break ; 
			pair < int , int > p ;
			p = *( -- ps.end() ) ; 
			if( p.f < ls ) break ; 
			//cout << p.f << " " << i << " dugu " <<endl ; 
			if( p.f != ls ) 
			v[ p.s ].pop_back() ;
			ps.erase( -- ps.end() ) ; 
		}
		ps.insert( { ls , x } ) ; 
	 }
	 int lst = 0 ; 
	 int bef = 0 ; 
	 for( auto x : ps ){
	 	int pos = x.f ; 
	 	while( lst < pos ){
	 		a[ lst ] = bef ;
	 		lst ++ ;
		 }
		 bef = x.second ; 
	 }
	pair < int , int > x = ( *--ps.end() ) ;
	int pos = x.f ; 
	while( lst < n ){
	 	a[ lst ] = x.s ;
	 	lst ++ ;
	}	 
//	debug ; 
	FOR( i , n ) cout << ma1[ a[ i ] ] << "\n" ; 
}
signed main() {
   ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
   int t = 1 ;// cin >> t ;
   while( t -- ){
   	 solve() ;
   }

}




Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:80:6: warning: unused variable 'pos' [-Wunused-variable]
   80 |  int pos = x.f ;
      |      ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...