Submission #368121

#TimeUsernameProblemLanguageResultExecution timeMemory
368121SortingSecret (JOI14_secret)C++17
100 / 100
514 ms4460 KiB
#include "secret.h" #include <bits/stdc++.h> const int N = 1000; const int LOGN = 11; int n, *a; int d[LOGN][N], mask[N]; void dnc(int l, int r, int bit){ if(l == r) return; int mid = (l + r) >> 1; d[bit][mid] = a[mid]; for(int i = mid - 1; i >= l; --i) d[bit][i] = Secret(a[i], d[bit][i + 1]); d[bit][mid + 1] = a[mid + 1]; for(int i = mid + 2; i <= r; ++i) d[bit][i] = Secret(d[bit][i - 1], a[i]); for(int i = mid + 1; i <= r; ++i) mask[i] ^= 1 << bit; dnc(l, mid, bit + 1), dnc(mid + 1, r, bit + 1); } void Init(int N, int A[]){ n = N, a = A; dnc(0, n - 1, 0); } int Query(int l, int r){ if(l == r) return a[r]; int bits = __builtin_ctz(mask[l] ^ mask[r]); return Secret(d[bits][l], d[bits][r]); }
#Verdict Execution timeMemoryGrader output
Fetching results...