# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1030497 |
2024-07-22T05:55:41 Z |
KienTran |
Secret (JOI14_secret) |
C++14 |
|
338 ms |
4444 KB |
#include <bits/stdc++.h>
#include "secret.h"
using namespace std;
const int O = 2e3 + 5;
//const int N = (1 << 20) + 5;
const int mod = 1e9 + 7; //998244353;
const int inf = 1e18;
int pr[] = {167772161, 469762049, 754974721, 1045430273, 1051721729, 1053818881};
const double eps = 1e-10;
int n, a[O], mask[O], f[21][O];
/*int Secret(int x, int y){
return x + (y / 2) * 2;
}*/
void DnC(int l, int r, int level){
if (l == r){
f[level][l] = a[l];
return;
}
int mid = (l + r) / 2;
f[level][mid] = a[mid];
for (int i = mid - 1; i >= l; -- i) f[level][i] = Secret(a[i], f[level][i + 1]);
f[level][mid + 1] = a[mid + 1];
for (int i = mid + 2; i <= r; ++ i) f[level][i] = Secret(f[level][i - 1], a[i]);
for (int i = mid + 1; i <= r; ++ i) mask[i] |= (1 << level);
DnC(l, mid, level + 1);
DnC(mid + 1, r, level + 1);
}
void Init(int N, int A[]){
for (int i = 0; i < N; ++ i){
a[i] = A[i];
mask[i] = 0;
}
DnC(0, N - 1, 0);
}
int Query(int L, int R){
if (L == R) return a[L];
if (L + 1 == R){
return Secret(a[L], a[R]);
}
int x = __builtin_ctz(mask[L] ^ mask[R]);
//cout << x << " " << f[x][L] << " " << f[x][R] << endl;
return Secret(f[x][L], f[x][R]);
}
/*main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cout << Secret(1, 4) << " " << Secret(7, 2) << endl;
cin >> n;
for (int i = 0; i < n; ++ i){
cin >> a[i];
}
Init(n, a);
int q; cin >> q;
while (q --){
int l, r; cin >> l >> r;
cout << Query(l, r) << endl;
}
}*/
/**
**/
Compilation message
secret.cpp:9:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
9 | const int inf = 1e18;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
2452 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
91 ms |
2396 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
92 ms |
2520 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
326 ms |
4356 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
318 ms |
4444 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
336 ms |
4376 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
314 ms |
4440 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
309 ms |
4436 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
317 ms |
4292 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
338 ms |
4436 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |