# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
483072 | Yazan_Alattar | Secret (JOI14_secret) | C++14 | 439 ms | 9000 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <utility>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 2007;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#include "secret.h"
int n, sum[M][M], a[M];
void solve(int l, int r)
{
if(l >= r) return;
int mid = (l + r) / 2;
sum[mid][mid] = a[mid];
sum[mid + 1][mid + 1] = a[mid + 1];
for(int i = mid - 1; i >= l; --i) sum[i][mid] = Secret(a[i], sum[i + 1][mid]);
for(int i = mid + 2; i <= r; ++i) sum[mid + 1][i] = Secret(sum[mid + 1][i - 1], a[i]);
solve(l, mid);
solve(mid + 1, r);
return;
}
int get(int st, int en, int l, int r)
{
int mid = (l + r) / 2;
if(en > mid && st <= mid) return Secret(sum[st][mid], sum[mid + 1][en]);
if(en <= mid) return get(st, en, l, mid);
return get(st, en, mid + 1, r);
}
void Init(int N, int A[])
{
n = N;
for(int i = 1; i <= n; ++i) a[i] = A[i - 1];
solve(1, n);
return;
}
int Query(int l, int r)
{
++l; ++r;
if(l == r) return a[l];
return get(l, r, 1, n);
}
// Don't forget special cases. (n = 1?)
// Look for the constraints. (Runtime array? overflow?)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |