Submission #977789

#TimeUsernameProblemLanguageResultExecution timeMemory
977789NoLoveSecret (JOI14_secret)C++14
100 / 100
395 ms4516 KiB
#include "secret.h" /** * author : Lăng Trọng Đạt * created: 08-05-2024 **/ #include <bits/stdc++.h> using namespace std; #ifndef LANG_DAT #define db(...) ; #endif // LANG_DAT // #define int long long #define mp make_pair #define f first #define se second #define pb push_back #define all(v) (v).begin(), (v).end() using pii = pair<int, int>; using vi = vector<int>; #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++) void mx(int& a, int b) { if (b > a) a = b; } void mi(int& a, int b) { if (b < a) a = b; } #define si(x) (int)(x.size()) const int INF = 1e18; const int MOD = 1e9 + 7; const int MAXN = 1e3 + 5; int g[MAXN]; int n; int mask[MAXN]; int dat[12][MAXN]; void build(int l, int r, int lv) { if (l != r) { int m = (l + r) / 2; dat[lv][m] = g[m]; for (int i = m - 1; i >= l; i--) { dat[lv][i] = Secret(g[i], dat[lv][i + 1]); } dat[lv][m + 1] = g[m + 1]; mask[m + 1] ^= 1 << lv; for (int i = m + 2; i <= r; i++) { dat[lv][i] = Secret(dat[lv][i - 1], g[i]); mask[i] ^= 1 << lv; } build(l, m, lv + 1); build(m + 1, r, lv + 1); } } void Init(int N, int A[]) { n = N; FOR(i, 0, n - 1) g[i] = A[i]; build(0, n - 1, 0); } int Query(int L, int R) { if (L == R) return g[L]; else { int bit = __builtin_ctz(mask[L] ^ mask[R]); return Secret(dat[bit][L], dat[bit][R]); } return 0; }

Compilation message (stderr)

secret.cpp:23:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   23 | const int INF = 1e18;
      |                 ^~~~
secret.cpp: In function 'void Init(int, int*)':
secret.cpp:19:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   19 | #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
      |                               ^
secret.cpp:53:2: note: in expansion of macro 'FOR'
   53 |  FOR(i, 0, n - 1) g[i] = A[i];
      |  ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...