#include "game.h"
#include <bits/stdc++.h>
using namespace std;
long long gcd2(long long X, long long Y) {
long long tmp;
while (X != Y && Y != 0) {
tmp = X;
X = Y;
Y = tmp % Y;
}
return X;
}
typedef pair<int,int> ii;
struct pair_hash
{
template <class T1, class T2>
std::size_t operator() (const std::pair<T1, T2> &pair) const
{
return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
}
};
static unordered_map<ii, long long, pair_hash> tree;
int N, M;
void init(int R, int C) {
N = R; M = C;
return;
}
void update(int r, int c, long long v) {
int nr = N + r;
int nc = M + c;
tree[ii(nr,nc)] = v;
while(nr > 0){
nc = M + c;
while(nc > 0){
if(nr < N){
tree[ii(nr,nc)] = gcd2(tree[ii(nr<<1,nc)],tree[ii(nr<<1|1,nc)]);
}
else if(nc < M){
tree[ii(nr,nc)] = gcd2(tree[ii(nr,nc<<1)],tree[ii(nr,nc<<1|1)]);
}
else tree[ii(nr,nc)] = v;
nc >>= 1;
}
nr >>= 1;
}
}
long long calculate(int t, int l, int b, int r) {
long long ans = 0;
b++; r++;
for(t += N, b += N;t < b;t >>= 1, b >>= 1){
if(t&1){
for(int nl = l+M, nr = r+M;nl < nr;nr >>= 1, nl >>= 1){
if(nl&1){
ans = gcd2(ans, tree[ii(t,nl)]);
//cout << t << " " << nl << "\n";
nl++;
}
if(nr&1){
nr--;
ans = gcd2(ans, tree[ii(t,nr)]);
//cout << t << " " << nr << "\n";
}
}
t++;
}
if(b&1){
b--;
for(int nl = l+M, nr = r+M;nl < nr;nr >>= 1, nl >>= 1){
if(nl&1){
ans = gcd2(ans, tree[ii(b,nl)]);
//cout << b << " " << nl << "\n";
nl++;
}
if(nr&1){
nr--;
ans = gcd2(ans, tree[ii(b,nr)]);
//cout << b << " " << nr << "\n";
}
}
}
}
//cout << endl;
return ans;
}
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;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
7 ms |
732 KB |
Output is correct |
3 |
Correct |
7 ms |
760 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
6 ms |
632 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
632 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3805 ms |
37632 KB |
Output is correct |
5 |
Correct |
2227 ms |
39812 KB |
Output is correct |
6 |
Correct |
5687 ms |
90176 KB |
Output is correct |
7 |
Correct |
5895 ms |
89912 KB |
Output is correct |
8 |
Correct |
4513 ms |
87112 KB |
Output is correct |
9 |
Correct |
5973 ms |
91456 KB |
Output is correct |
10 |
Correct |
5587 ms |
89600 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
7 ms |
760 KB |
Output is correct |
3 |
Correct |
8 ms |
760 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
632 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
632 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Execution timed out |
13025 ms |
17540 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
7 ms |
760 KB |
Output is correct |
3 |
Correct |
7 ms |
760 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
632 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
632 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
4056 ms |
37524 KB |
Output is correct |
13 |
Correct |
2231 ms |
39816 KB |
Output is correct |
14 |
Correct |
5646 ms |
90084 KB |
Output is correct |
15 |
Correct |
5792 ms |
89772 KB |
Output is correct |
16 |
Correct |
4520 ms |
87020 KB |
Output is correct |
17 |
Correct |
5702 ms |
91616 KB |
Output is correct |
18 |
Correct |
5521 ms |
89568 KB |
Output is correct |
19 |
Execution timed out |
13057 ms |
19020 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
8 ms |
764 KB |
Output is correct |
3 |
Correct |
7 ms |
760 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
632 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
6 ms |
632 KB |
Output is correct |
10 |
Correct |
4 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3965 ms |
37508 KB |
Output is correct |
13 |
Correct |
2235 ms |
39940 KB |
Output is correct |
14 |
Correct |
5834 ms |
90076 KB |
Output is correct |
15 |
Correct |
6005 ms |
89900 KB |
Output is correct |
16 |
Correct |
4972 ms |
87032 KB |
Output is correct |
17 |
Correct |
5707 ms |
91580 KB |
Output is correct |
18 |
Correct |
5590 ms |
89692 KB |
Output is correct |
19 |
Execution timed out |
13093 ms |
18452 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |