# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1069473 |
2024-08-22T01:53:57 Z |
Requiem |
Secret (JOI14_secret) |
C++17 |
|
0 ms |
0 KB |
//#include "secret.h"
#include<bits/stdc++.h>
#define ll long long
#define FOR(i, a, b) for(int i = a; i <= b;i++)
#define FORD(i, a, b) for(int i = a; i >= b; i--)
#define TASKNAME "secret"
using namespace std;
const int MAX_VALUE = 1e9;
int Secret(int X, int Y) {
if (!(0 <= X && X <= MAX_VALUE)) {
fprintf(stderr, "Wrong Answer [1]\n");
exit(0);
}
if (!(0 <= Y && Y <= MAX_VALUE)) {
fprintf(stderr, "Wrong Answer [1]\n");
exit(0);
}
return (X + 2 * (Y / 2) < MAX_VALUE) ? (X + 2 * (Y / 2)) : MAX_VALUE;
}
const int MAXN = 1004;
int P[20][MAXN], mask[MAXN], a[MAXN];
int n, q;
void DnC(int l, int r, int lev){
if (l == r){
return;
}
int mid = (l + r) >> 1;
P[lev][mid] = a[mid];
P[lev][mid + 1] = a[mid + 1];
// printf("RANGE %lld %lld\n", l, r);
FORD(i, mid - 1, l){
P[lev][i] = Secret(a[i], P[lev][i + 1]);
}
// FORD(i, mid, l){
// printf("%lld ", P[lev][i]);
// }
// printf("\n");
FOR(i, mid + 2, r){
P[lev][i] = Secret(P[lev][i - 1], a[i]);
}
// FOR(i, mid + 1, r){
// printf("%lld ", P[lev][i]);
// }
// printf("\n");
FOR(i, mid + 1, r) mask[i] ^= (1LL << lev);
DnC(l, mid, lev + 1);
DnC(mid + 1, r, lev + 1);
}
void Init(int N, int A[]) {
FOR(i, 0, N - 1){
a[i] = A[i];
}
DnC(0, N - 1, 0);
}
int Query(int L, int R) {
if (L == R) return a[L];
else{
int bit = __builtin_ctz(mask[L] ^ mask[R]);
// printf("%lld %lld %lld\n", bit, P[bit][L], P[bit][R]);
return Secret(P[bit][L], P[bit][R]);
}
return 0;
}
main(){
freopen(TASKNAME".inp","r",stdin);
freopen(TASKNAME".out","w",stdout);
cin >> n;
FOR(i, 0, n - 1){
cin >> a[i];
}
Init(n, a);
cin >> q;
FOR(i, 0, q - 1){
int l, r;
cin >> l >> r;
printf("%d\n", Query(l, r));
}
}
Compilation message
secret.cpp:73:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
73 | main(){
| ^~~~
secret.cpp: In function 'int main()':
secret.cpp:74:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | freopen(TASKNAME".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
secret.cpp:75:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
75 | freopen(TASKNAME".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccPSOf2u.o: in function `Secret(int, int)':
secret.cpp:(.text+0x0): multiple definition of `Secret(int, int)'; /tmp/ccpfXIgw.o:grader.cpp:(.text+0x2d0): first defined here
/usr/bin/ld: /tmp/ccPSOf2u.o: in function `main':
secret.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccpfXIgw.o:grader.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status