# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
99163 |
2019-03-01T09:05:31 Z |
jhnah917 |
Game (IOI13_game) |
C++14 |
|
4 ms |
896 KB |
#ifndef __GAME_H__
#define __GAME_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <math.h>
void init(int R, int C);
void update(int P, int Q, long long K);
long long calculate(int P, int Q, int U, int V);
int r, c;
typedef long long ll;
long long f(long long X, long long Y) {
long long tmp;
while (X != Y && Y != 0) {
tmp = X;
X = Y;
Y = tmp % Y;
}
return X;
}
struct Seg1d{
ll *arr;
int lim;
void init(int n){
for(lim=1; lim<n; lim<<=1);
arr = new ll[lim*2];
}
void update(int idx, ll val){
idx |= lim;
arr[idx] = val;
while(idx >>= 1) arr[idx] = f(arr[idx*2], arr[idx*2+1]);
}
ll query(int l, int r){
ll lval = 0, rval = 0;
l |= lim, r |= lim;
while(l <= r){
if(l&1) lval = f(lval, arr[l++]);
if(!(r&1)) rval = f(rval, arr[r--]);
l >>= 1, r >>= 1;
}
return f(lval, rval);
}
Seg1d(){
init(c);
}
};
struct Seg2d{
Seg1d *arr;
int lim;
void init(int n){
for(lim=1; lim<n; lim<<=1);
arr = new Seg1d[lim*2];
}
void update(int x, int y, ll val){
x |= lim;
arr[x].update(y, val);
while(x >>= 1){
arr[x].update(y, val);
}
}
ll query(int x1, int x2, int y1, int y2){
ll ret = 0;
x1 |= lim, x2 |= lim;
while(x1 <= x2){
if(x1 & 1) ret = f(ret, arr[x1++].query(y1, y2));
if(!(x2 & 1)) ret = f(ret, arr[x2--].query(y1, y2));
x1 >>= 1; x2 >>= 1;
}
return ret;
}
Seg2d(){
init(r);
}
} tree;
void init(int R, int C) {
r = R, c = C;
tree = Seg2d();
}
void update(int x, int y, long long val) {
tree.update(x, y, val);
}
long long calculate(int x1, int y1, int x2, int y2) {
return tree.query(x1, x2, y1, y2);
}
#ifdef __cplusplus
}
#endif
#endif /* __GAME_H__ */
Compilation message
grader.c: In function 'int main()':
grader.c:18:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
int res;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
4 ms |
768 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Incorrect |
3 ms |
896 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
3 ms |
768 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Incorrect |
3 ms |
768 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |