Submission #931683

# Submission time Handle Problem Language Result Execution time Memory
931683 2024-02-22T09:12:53 Z thunopro Xylophone (JOI18_xylophone) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std ; 
#define maxn 200009
#define ll long long 
#define pb push_back 
#define fi first 
#define se second 
#define left id<<1
#define right id<<1|1 
#define re exit(0); 
#define _lower(x) lower_bound(v.begin(),v.end(),x)-v.begin()+1
const int mod = 1e9+7 ;
const int INF = 1e9 ; 

typedef vector<int> vi ; 
typedef pair<int,int> pii ; 
typedef vector<pii> vii ; 

template < typename T > void chkmin ( T &a , T b ) { if ( a > b ) a = b ; } 
template < typename T > void chkmax ( T &a , T b ) { if ( a < b ) a = b ; } 

void add ( int &a , int b ) 
{
	a += b ; 
	if ( a >= mod ) a -= mod ; 
	if ( a < 0 ) a += mod ; 
}

void rf () 
{
	freopen ("bai1.inp","r",stdin) ;
}

int _pow ( int a , int n ) 
{
	if ( n == 0 ) return 1 ; 
	int res = _pow (a,n/2) ; 
	if ( n % 2 ) return 1ll*res*res%mod*a%mod ; 
	else return 1ll*res*res%mod ; 
}

int n ; 
int a [maxn] ; 
bool used [maxn] ; 
//int query ( int l , int r ) 
//{
//	cout << l << " " << r << endl ; 
//	int x ; cin >> x ; 
//	return x ; 
//}

void assign ( int &x , int y ) 
{
	x = y ; 
	used [y] = true ; 
}
bool ban ( int x ) 
{
	return ( x <= 0 || x > n || used [x] ) ; 
}
void solve ( int N ) 
{
	n = N ; 
	int pos1 ; 
	int l = 1 , r = n-1 ; 
	while ( l <= r ) 
	{
		int mid = (l+r)/2 ; 
		if ( query (mid,n) == n-1 ) pos1 = mid , l = mid + 1 ; 
		else r = mid - 1 ; 
	}
	a [pos1] = 1 , used [1] = true ; 
	if ( pos1 > 1 ) 
	{
		assign (a[pos1-1],1+query(pos1-1,pos1)) ; 
		for ( int i = pos1-2 ; i >= 1 ; i -- ) 
		{
			int diff1 = query (i,i+1) ; 
			if ( ban (a[i+1]-diff1) ) assign (a[i],a[i+1]+diff1) ; 
			else if ( ban (a[i+1]+diff1) ) assign (a[i],a[i+1]-diff1) ; 
			else 
			{
				int diff2 = query (i,i+2) ; 
				if ( diff1 == diff2 ) 
				{
					if ( a [i+1] < a [i+2] ) assign (a[i],a[i+1]+diff1) ; 
					else assign (a[i],a[i+1]-diff1) ; 
				}
				else 
				{
					if ( a [i+1] < a [i+2] ) assign (a[i],a[i+1]-diff1) ; 
					else assign (a[i],a[i+1]+diff1) ; 
				}
			}
		}
	}
	if ( pos1 < n ) 
	{
		assign (a[pos1+1],1+query(pos1,pos1+1)) ; 
		for ( int i = pos1+2 ; i <= n ; i ++ ) 
		{
			int diff1 = query (i-1,i) ; 
			if ( ban (a[i-1]-diff1) ) assign (a[i],a[i-1]+diff1) ;
			else if ( ban (a[i-1]+diff1) ) assign (a[i],a[i-1]-diff1) ; 
			else 
			{
				int diff2 = query (i-2,i) ; 
				if ( diff1 == diff2 )
				{
					if ( a [i-2] < a [i-1] ) assign (a[i],a[i-1]-diff1) ; 
					else assign (a[i],a[i-1]+diff1) ; 
				}
				else 
				{
					if ( a [i-2] < a [i-1] ) assign (a[i],a[i-1]+diff1) ; 
					else assign (a[i],a[i-1]-diff1) ; 
				}
			}
		}
	}
//	for ( int i = 1 ; i <= n ; i ++ ) cout << a [i] << " " ; 
	for ( int i = 1 ; i <= n ; i ++ ) answer (i,a[i]) ; 
}
//int main () 
//{
//	ios_base::sync_with_stdio(0); 
//	cin.tie(0);cout.tie(0); 
////	rf () ; 
//	solve (5) ; 
//}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:69:8: error: 'query' was not declared in this scope
   69 |   if ( query (mid,n) == n-1 ) pos1 = mid , l = mid + 1 ;
      |        ^~~~~
xylophone.cpp:75:23: error: 'query' was not declared in this scope
   75 |   assign (a[pos1-1],1+query(pos1-1,pos1)) ;
      |                       ^~~~~
xylophone.cpp:99:23: error: 'query' was not declared in this scope
   99 |   assign (a[pos1+1],1+query(pos1,pos1+1)) ;
      |                       ^~~~~
xylophone.cpp:122:36: error: 'answer' was not declared in this scope
  122 |  for ( int i = 1 ; i <= n ; i ++ ) answer (i,a[i]) ;
      |                                    ^~~~~~
xylophone.cpp: In function 'void rf()':
xylophone.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  freopen ("bai1.inp","r",stdin) ;
      |  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~