# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
348828 |
2021-01-15T20:29:22 Z |
spatarel |
Secret (JOI14_secret) |
C++17 |
|
502 ms |
4972 KB |
#include "secret.h"
#include <map>
struct StructQuery {
int left;
int right;
};
bool operator < (const StructQuery &a, const StructQuery &b) {
return (a.left < b.left)
|| (a.left == b.left && a.right < b.right);
}
int n;
std::map<StructQuery, int> secrets;
void querySecrets(int left, int right, int A[]) {
if (left == right) {
secrets[StructQuery{left, right}] = A[left];
} else {
int avg = (left + right) / 2;
secrets[StructQuery{avg, avg}] = A[avg];
for (int i = avg - 1; i >= left; i--) {
secrets[StructQuery{i, avg}] =
Secret(A[i], secrets[StructQuery{i + 1, avg}]);
}
secrets[StructQuery{avg + 1, avg + 1}] = A[avg + 1];
for (int i = avg + 2; i <= right; i++) {
secrets[StructQuery{avg + 1, i}] =
Secret(secrets[StructQuery{avg + 1, i - 1}], i);
}
querySecrets(left, avg, A);
querySecrets(avg + 1, right, A);
}
}
void Init(int N, int A[]) {
n = N;
querySecrets(0, N - 1, A);
}
int Query(int L, int R) {
int left = 0;
int right = n - 1;
while (true) {
int avg = (left + right) / 2;
if (R == avg || L == avg + 1) {
return secrets[StructQuery{L, R}];
} else if (L <= avg && avg + 1 <= R) {
return Secret(secrets[StructQuery{L, avg}], secrets[StructQuery{avg + 1, R}]);
} else if (R < avg) {
right = avg;
} else { // avg + 1 < L
left = avg + 1;
}
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
132 ms |
2668 KB |
Wrong Answer: Query(222, 254) - expected : 34031541, actual : 272722698. |
2 |
Incorrect |
133 ms |
2668 KB |
Wrong Answer: Query(60, 375) - expected : 669221184, actual : 841488713. |
3 |
Incorrect |
134 ms |
2668 KB |
Wrong Answer: Query(211, 401) - expected : 674373968, actual : 478273654. |
4 |
Incorrect |
498 ms |
4972 KB |
Wrong Answer: Query(90, 497) - expected : 397934825, actual : 300941931. |
5 |
Incorrect |
495 ms |
4844 KB |
Wrong Answer: Query(587, 915) - expected : 752404486, actual : 459821058. |
6 |
Incorrect |
502 ms |
4972 KB |
Wrong Answer: Query(738, 741) - expected : 983692994, actual : 8536157. |
7 |
Incorrect |
500 ms |
4844 KB |
Wrong Answer: Query(84, 976) - expected : 742463504, actual : 757106754. |
8 |
Incorrect |
499 ms |
4844 KB |
Wrong Answer: Query(58, 987) - expected : 20022464, actual : 480621968. |
9 |
Incorrect |
497 ms |
4972 KB |
Wrong Answer: Query(33, 967) - expected : 676869696, actual : 22035146. |
10 |
Incorrect |
500 ms |
4972 KB |
Wrong Answer: Query(116, 961) - expected : 68487362, actual : 541248776. |