Submission #934991

# Submission time Handle Problem Language Result Execution time Memory
934991 2024-02-28T09:59:33 Z vjudge1 Secret (JOI14_secret) C++17
100 / 100
389 ms 11356 KB
#include <bits/stdc++.h>
#include <secret.h>
 
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back //emplace_back
#define pp pop_back
#define pii pair<ll, ll> //pair<int, int>
#define all(x) (x).begin(),(x).end()
#define mp(a,b) make_pair(a , b)
#define lb lower_bound
#define ub upper_bound
#define sz(x) (ll)(x).size()
#define F first
#define S second x) (x).begin()
#define For(x, n) for(int (x) = 0 ; (x) < (n) ; (x)++)
#define debug(x) cout << #x << " : " << x << endl << flush
#define endl '\n'
#define arr(x) array<ll , (x)>
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);
 
ll Sum(ll a , ll b , ll MOD)
{
 a %= MOD;
 b %= MOD;
 a += b;
 return a % MOD;
}
 
ll Mul(ll a , ll b , ll MOD)
{
 a %= MOD;
 b %= MOD;
 a *= b;
 return a % MOD;
}
 
ll Pow(ll a , ll b , ll MOD)
{
   ll res = 1;
   while(b)
   {
        if((b & 1))res = Mul(res , a , MOD);
     a = Mul(a , a , MOD);
     b >>= 1;
   }
   return res;
}
 
ll Min(ll a , ll b)
{
   if(a > b)return b;
   return a;
}
 
ll Max(ll a , ll b)
{
   if(a > b)return a;
   return b;
}
 
ll Ceil(ll a , ll b)
{
 if(b < 0)
  a *= -1, b *= -1;
 
 if(a < 0)return a/b;
 
 return(a + (b-1))/b;
}
 
/////////////////////
//VALS
const ll maxn = 1000;
ll a[maxn];
ll n;
ll ans[maxn][maxn];
/////////////////////
//FUNS
void f(ll L, ll R)
{
	int mid = (L + R) / 2;
	ans[mid][mid] = a[mid];
	ans[mid + 1][mid + 1] = a[mid + 1];
 
	for (int i = mid + 2; i <= R; i++)
		ans[mid + 1][i] = Secret(ans[mid + 1][i - 1], a[i]);
		
	for (int i = mid - 1; i >= L; i--)
		ans[mid][i] = Secret(a[i], ans[mid][i + 1]);
 
	if (L < mid) f(L, mid);
	if (mid + 1 < R) f(mid + 1, R);
}
 
void Init(int N, int A[]) 
{
	n = N;
	For(i,N)a[i] = A[i];
	f(0 , n-1);
}
 
int Query(int L, int R) 
{
	int a = 0, b = n-1;
 
	while (a != b) {
		int mid = (a + b) / 2;
		if (mid >= L && mid < R)
			return Secret(ans[mid][L], ans[mid + 1][R]);
		else if (mid == R) return ans[mid][L];
		else if (mid < L) a = mid + 1;
		else b = mid;
	}

	return ans[a][a];
}
/////////////////////
/*
ZZZZZZZ     A        M     M     IIIIIII  N     N
     Z     A A      M M   M M       I     NN    N
    Z     A   A    M   M M   M      I     N N   N
   Z     AAAAAAA  M     M     M     I     N  N  N
  Z      A     A  M           M     I     N   N N
 Z       A     A  M           M     I     N    NN
ZZZZZZZ  A     A  M           M  IIIIIII  N     N  TREE
*/

Compilation message

secret.cpp: In function 'void Init(int, int*)':
secret.cpp:18:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   18 | #define For(x, n) for(int (x) = 0 ; (x) < (n) ; (x)++)
      |                           ^
secret.cpp:103:2: note: in expansion of macro 'For'
  103 |  For(i,N)a[i] = A[i];
      |  ^~~
# Verdict Execution time Memory Grader output
1 Correct 111 ms 8804 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 112 ms 9216 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 119 ms 8784 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 381 ms 11352 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 384 ms 11348 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 379 ms 11352 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 381 ms 11352 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 389 ms 11356 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 386 ms 11352 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 386 ms 11352 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1