#include <bits/stdc++.h>
#include "secret.h"
#define ll long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define pi pair<int,int>
#define pii pair<int,pi>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) (int) a.size()
#define endl '\n'
#define data "secret"
using namespace std;
const ll linf = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7, MX = 1e5;
void add(int &a, int b)
{
a += b;
if(a>=MOD)
a-=MOD;
if(a<0)
a += MOD;
}
int modulo(int x)
{
if(x<=1)
return 1;
return (MOD - MOD/x) * modulo(MOD/x) % MOD;
}
int mul(int a, int b)
{
return (1ll *a%MOD * b%MOD) % MOD;
}
int type;
int n;
int a[MX+3];
int acc[MX+3][23];
int mask[MX+3];
int calc(int a, int b)
{
if(type == 1) return a + b;
if(type == 2) return a - b;
if(type == 3) return a * b;
if(type == 4) return a / b;
}
void DnC(int l, int r, int lvl)
{
if(l == r) return;
int mid = (l+r) >> 1;
DnC(l, mid, lvl + 1);
DnC(mid + 1, r, lvl + 1);
acc[mid][lvl] = a[mid];
ROF(i, mid - 1, l) acc[i][lvl] = calc(a[i], acc[i+1][lvl]);
acc[mid+1][lvl] = a[mid+1];
FOR(i, mid + 2, r) acc[i][lvl] = calc(a[i], acc[i-1][lvl]);
FOR(i, mid + 1, r) mask[i] |= (1 << lvl);
}
void Init(int N, int A[])
{
n = N;
FOR(i, 0, n - 1) a[i] = A[i];
int tmp = Secret(8, 2);
if(tmp == 10) type = 1;
if(tmp == 6) type = 2;
if(tmp == 16) type = 3;
if(tmp == 4) type = 4;
DnC(0, n - 1, 0);
}
int Query(int L, int R)
{
if(L == R) return a[L];
int k = __builtin_ctz( mask[L] ^ mask[R] );
return calc(acc[L][k], acc[R][k]);
}
Compilation message (stderr)
secret.cpp: In function 'int calc(int, int)':
secret.cpp:54:1: warning: control reaches end of non-void function [-Wreturn-type]
54 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |