Submission #781491

# Submission time Handle Problem Language Result Execution time Memory
781491 2023-07-13T06:55:59 Z lollipop Gondola (IOI14_gondola) C++17
100 / 100
56 ms 10220 KB
#include "gondola.h"
#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 long long mod =  1000000009 ;
const int mod1 = 998244353 ;
const int N = 2e6 + 10 ;
mt19937 R(time(0));
map < int , int > ma , ma1 ;


int valid(int n, int a[]){
    int pos = 0 ;
    FOR( i , n ){
    	if( a[ i ] <= n ){
    		pos = i ; break ; 
		}
	}
	ma.clear() ;
    FOR( i , n ) if( a[ i ] == 0 ){
    	return 0 ; 
	} 
	FOR( i , n ){
		if( ma[ a[ i ] ] == 1 ) return 0 ;
		ma[ a[ i ] ] = 1 ; 
	} 
	int j = pos , cur = a[ pos ] ; 
	while( true ){
		if( a[ j ] <= n ){
			if( a[ j ] != cur ) return 0 ;
		}
		cur ++ ; if( cur == n + 1 ) cur = 1 ;
		j ++ ; j %= n ; 
		if( j == pos ) break ; 
	}
	return 1 ;
}
int replacement(int n, int a[], int replacementSeq[]){
    int mx = 0 , mn = INT_MAX ;
    int b[ n ] ;
    set < int > se ; 
    FOR( i , n ){
    	mn = min( mn , a[ i ] ) ;
    	mx = max( mx , a[ i ] ) ;
	}
	for( int j = n + 1 ; j <= mx ; j ++ ) se.insert( j ) ;
//	FOR( i , n ){
//		if( a[ i ] > n ) se.erase( se.find( a[ i ] ) ) ; 
//	}
    if( mn > n ){
    	FOR( i , n ) b[ i ] = i + 1 ; 
	}
    else{
       int pos = 0 ;
  	   FOR( i , n ){
     		if( a[ i ] <= n ){
    	 		pos = i ; break ; 
		 	}
	   }
		int j = pos , cur = a[ pos ] ; 
		while( true ){
			b[ j ] = cur ; 
			cur ++ ; if( cur == n + 1 ) cur = 1 ;
			j ++ ; j %= n ; 
			if( j == pos ) break ; 
		}	  
	}
    int cnt = 0 ;
    vector < pair < int , int > > v ; 
    FOR( i , n ){
    	if( a[ i ] == b[ i ] ) continue ;
    	v.pb( { a[ i ] , b[ i ] } ) ;
	}
    sort( v.begin() , v.end() ) ;
    for( auto x : v ){
    	int lst = x.s ;
    	int nd = x.f ;
    	while( true ){
    		int x = *se.begin() ;
    		replacementSeq[ cnt ] = lst ;
    		cnt ++ ;
    		lst = x ;
    		se.erase( se.begin() ) ;
    		//cout << x << " " << nd << endl ;
    		if( x == nd ) break ; 
		}
	}
	return cnt ;
}
long long pp( int X, int Y, int p)
{
	if( Y == 0 ) return 1 ;
	long long x = X , y = Y ; 
    int res = 1;
    while (y > 0) {
        if (y % 2 == 1)
            res = (res * x % p );
        y = y >> 1;
        x = (x * x % p );
    }
    return res % p;
}
 
vector < int > v ; 
int b[ N ] ;   
int countReplacement(int n, int a[]){
//	se.clear() ;
	v.clear();
    ma.clear() ;	
		    long long ans = 1 ;
    int x = valid( n , a ) ;
    if( x == 0 ) return 0 ; 
	int mx = 0 ;
	FOR( i , n ) mx = max( mx , a[ i ] ) ;
	if( mx <= n ) return 1 ; 


   int mn = INT_MAX ; 
    FOR( i , n ){
    	mn = min( mn , a[ i ] ) ;
    	mx = max( mx , a[ i ] ) ;
	}
//	for( int j = n + 1 ; j <= mx ; j ++ ) se.pb( j ) ;
    if( mn > n ){
    	ans = n ; 
    	FOR( i , n ) b[ i ] = i + 1 ; 
	}
    else{
       int pos = 0 ;
  	   FOR( i , n ){
     		if( a[ i ] <= n ){
    	 		pos = i ; break ; 
		 	}
	   }
		int j = pos , cur = a[ pos ] ; 
		while( true ){
			b[ j ] = cur ; 
			cur ++ ; if( cur == n + 1 ) cur = 1 ;
			j ++ ; j %= n ; 
			if( j == pos ) break ; 
		}	  
	}
    int cnt = 0 ;
    FOR( i , n ){
    	if( a[ i ] == b[ i ] ) continue ;
    	v.pb( a[ i ] ) ;
	}
    sort( v.begin() , v.end() ) ;
    long long lf = v.size() ;
	int st = 0 ; 
	int lst = n + 1 ; 
    for( auto x : v ){
   // 	int lst = x.s ;
    	int nd = x ;
    	long long y = pp( lf , nd - lst , mod ) ;
        ans = ans * y ;
        ans %= mod ; 
        lst = nd + 1 ; 
		lf -- ; 
	}	
	ans %= mod ; 
	int pas = ans ; 
	
	return ans ; 
		
}


//int gondolaSequence[100001];
//int replacementSequence[250001];
//
//int main() {
//  int i, n, tag;
//  int nr;
//  assert(scanf("%d", &tag) == 1);
//  assert(scanf("%d", &n) == 1);
//  for (i = 0; i < n; i++)
//    assert(scanf("%d", &gondolaSequence[i]) == 1);
//
//  switch (tag) {
//  case 1:
//  case 2:
//  case 3:
//    printf("%d\n", valid(n, gondolaSequence));
//    break;
//
//  case 4:
//  case 5:
//  case 6:
//    nr = replacement(n, gondolaSequence, replacementSequence);
//    printf("%d ", nr);
//    if (nr > 0) {
//      for (i = 0; i < nr - 1; i++)
//        printf("%d ", replacementSequence[i]);
//      printf("%d\n", replacementSequence[nr - 1]);
//    } else
//      printf("\n");
//    break;
//
//  case 7:
//  case 8:
//  case 9:
//  case 10:
//    printf("%d\n", countReplacement(n, gondolaSequence));
//    break;
//  }
//
//  return 0;
//}




Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:166:9: warning: unused variable 'cnt' [-Wunused-variable]
  166 |     int cnt = 0 ;
      |         ^~~
gondola.cpp:173:6: warning: unused variable 'st' [-Wunused-variable]
  173 |  int st = 0 ;
      |      ^~
gondola.cpp:185:6: warning: unused variable 'pas' [-Wunused-variable]
  185 |  int pas = ans ;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 10 ms 2128 KB Output is correct
7 Correct 7 ms 596 KB Output is correct
8 Correct 20 ms 3824 KB Output is correct
9 Correct 6 ms 1364 KB Output is correct
10 Correct 23 ms 4436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 11 ms 2132 KB Output is correct
7 Correct 7 ms 596 KB Output is correct
8 Correct 18 ms 3864 KB Output is correct
9 Correct 6 ms 1492 KB Output is correct
10 Correct 22 ms 4528 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 12 ms 2004 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 31 ms 4684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 224 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 7 ms 852 KB Output is correct
12 Correct 8 ms 980 KB Output is correct
13 Correct 21 ms 4652 KB Output is correct
14 Correct 7 ms 852 KB Output is correct
15 Correct 56 ms 10220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 32 ms 4620 KB Output is correct
10 Correct 28 ms 3988 KB Output is correct
11 Correct 10 ms 1748 KB Output is correct
12 Correct 12 ms 2004 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 37 ms 4720 KB Output is correct
10 Correct 29 ms 3964 KB Output is correct
11 Correct 10 ms 1744 KB Output is correct
12 Correct 12 ms 2020 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 55 ms 6348 KB Output is correct
15 Correct 48 ms 7052 KB Output is correct
16 Correct 8 ms 1620 KB Output is correct
17 Correct 32 ms 4720 KB Output is correct
18 Correct 19 ms 3028 KB Output is correct