Submission #1055240

#TimeUsernameProblemLanguageResultExecution timeMemory
1055240phongSecret (JOI14_secret)C++17
0 / 100
277 ms14952 KiB
#include<bits/stdc++.h> #include "secret.h" #define ll long long const int nmax = 1e3+ 5; using namespace std; int n, a[nmax]; int L[1 << 11][nmax], R[1 << 11][nmax]; //int Secret(int a, int b){ // if(a > b) swap(a, b); // if(a == 4 && b == 7) return 10; // if(a == 1 && b == 10) return 11; // if(a == 2 && b == 11) return 13; // return 0; //} void build(int id, int l, int r){ if(l == r)return; int mid = r + l >> 1; L[id][mid] = a[mid]; R[id][mid + 1] = a[mid + 1]; for(int i = mid - 1; i >= l; --i) L[id][i] = Secret(L[id][i + 1], a[i]); for(int i = mid + 2; i <= r; ++i) R[id][i] = Secret(R[id][i - 1], a[i]); build(id << 1, l, mid); build(id << 1 | 1, mid + 1, r); } int get(int id, int l, int r, int u, int v){ if(u == v) return a[u]; if(l > v || r < u) return 0; int mid = r + l >> 1; if (v == mid && l <= u) return L[id][u]; if(u == mid + 1 && v <= r) return R[id][v]; if(u <= mid && mid + 1 <= v){ return Secret(L[id][u], R[id][v]); } return get(id << 1, l, mid, u, v) + get(id << 1 | 1, mid + 1, r, u, v); } void Init(int NA, int A[]){ n = NA; for(int i = 1; i <= n; ++i) a[i] = A[i - 1]; build(1, 1, n); } int Query(int a, int b){ ++a, ++b; return get(1, 1, n, a, b); }

Compilation message (stderr)

secret.cpp: In function 'void build(int, int, int)':
secret.cpp:21:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |     int mid = r + l >> 1;
      |               ~~^~~
secret.cpp: In function 'int get(int, int, int, int, int)':
secret.cpp:34:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   34 |     int mid = r + l >> 1;
      |               ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...