# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
281892 |
2020-08-23T15:24:41 Z |
Saboon |
Game (IOI13_game) |
C++14 |
|
7651 ms |
13756 KB |
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int SQ = 150;
ll gcd2(ll X, ll Y){
ll tmp;
while (X != Y && Y != 0){
tmp = X;
X = Y;
Y = tmp % Y;
}
return X;
}
ll seg[SQ+100][8*SQ+100];
ll get(int id, int L, int R, int l, int r, int block){
if (r <= L or R <= l)
return 0;
if (l <= L and R <= r)
return seg[block][id];
int mid = (L + R) >> 1;
return gcd2(get(2*id+0, L, mid, l, r, block),
get(2*id+1, mid, R, l, r, block));
}
void change(int id, int L, int R, int idx, ll K, int block){
if (idx < L or R <= idx)
return;
if (L + 1 == R){
seg[block][id] = K;
return;
}
int mid = (L + R) >> 1;
change(2*id+0, L, mid, idx, K, block);
change(2*id+1, mid, R, idx, K, block);
seg[block][id] = gcd2(seg[block][2*id+0], seg[block][2*id+1]);
}
int numBlock;
vector<pair<pair<int,int>,ll>> a[100+SQ];
map<pair<int,int>, ll> mp;
map<pair<int,int>, int> go;
vector<pair<int,ll>> b[SQ+100];
void changeblock(int block){
assert(a[block].size() < 2*SQ);
sort(a[block].begin(), a[block].end());
for (int i = 0; i < 8*SQ; i++)
seg[block][i] = 0;
b[block].clear();
for (auto it : a[block])
b[block].push_back({it.first.second,it.second});
sort(b[block].begin(), b[block].end());
for (int i = 0; i < b[block].size(); i++)
change(1, 0, b[block].size(), i, b[block][i].second, block);
}
void refresh(){
go.clear();
for (int i = 0; i < SQ; i++){
a[i].clear();
a[i].shrink_to_fit();
}
int n = mp.size();
int idx = -1;
numBlock = 1;
for (auto it : mp){
idx ++;
numBlock = idx/SQ + 1;
go[it.first] = idx/SQ;
a[idx/SQ].push_back(it);
}
for (int i = 0; i < numBlock; i++)
changeblock(i);
}
void init(int R, int C){
numBlock = 1;
}
void update(int P, int Q, ll K){
if (mp.count({P,Q})){
mp[{P,Q}] = K;
int block = go[{P,Q}];
assert(block < SQ);
for (int i = 0; i < a[block].size(); i++)
if (a[block][i].first == make_pair(P,Q))
a[block][i].second = K;
changeblock(block);
assert(block == numBlock-1 or a[block].back().first.first <= a[block+1][0].first.first);
if (block == 0)
return;
block --;
assert(block == numBlock-1 or a[block].back().first.first <= a[block+1][0].first.first);
return;
}
mp[{P,Q}] = K;
int block = numBlock-1;
for (int i = numBlock-1; i >= 1; i--)
if (P <= a[i][0].first.first)
block = i-1;
go[{P,Q}] = block;
a[block].push_back({{P,Q},K});
if (a[block].size() >= 2*SQ)
refresh();
else
changeblock(block);
}
ll calculate(int P, int Q, int U, int V){
ll answer = 0;
for (int i = 0; i < numBlock; i++){
if (a[i].empty())
continue;
if (a[i][0].first.first > U)
break;
if (a[i].back().first.first < P)
continue;
if (a[i][0].first.first >= P and a[i].back().first.first <= U){
int lo = lower_bound(b[i].begin(), b[i].end(), make_pair(Q,-1LL)) - b[i].begin();
int hi = lower_bound(b[i].begin(), b[i].end(), make_pair(V+1, -1LL)) - b[i].begin();
answer = gcd2(answer, get(1, 0, b[i].size(), lo, hi, i));
continue;
}
for (auto it : a[i]){
int p = it.first.first, q = it.first.second;
ll x = it.second;
if (P <= p and p <= U and Q <= q and q <= V)
answer = gcd2(answer, x);
}
}
return answer;
}
Compilation message
grader.c: In function 'int main()':
grader.c:18:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
18 | int res;
| ^~~
game.cpp: In function 'void changeblock(int)':
game.cpp:57:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int i = 0; i < b[block].size(); i++)
| ~~^~~~~~~~~~~~~~~~~
game.cpp: In function 'void refresh()':
game.cpp:67:6: warning: unused variable 'n' [-Wunused-variable]
67 | int n = mp.size();
| ^
game.cpp: In function 'void update(int, int, ll)':
game.cpp:90:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for (int i = 0; i < a[block].size(); i++)
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1726 ms |
7232 KB |
Output is correct |
5 |
Correct |
1195 ms |
7432 KB |
Output is correct |
6 |
Correct |
1701 ms |
4216 KB |
Output is correct |
7 |
Correct |
1782 ms |
3704 KB |
Output is correct |
8 |
Correct |
893 ms |
3192 KB |
Output is correct |
9 |
Correct |
1714 ms |
3800 KB |
Output is correct |
10 |
Correct |
1664 ms |
3484 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
2394 ms |
6660 KB |
Output is correct |
13 |
Correct |
3794 ms |
2896 KB |
Output is correct |
14 |
Correct |
910 ms |
972 KB |
Output is correct |
15 |
Correct |
3825 ms |
2936 KB |
Output is correct |
16 |
Correct |
1273 ms |
3192 KB |
Output is correct |
17 |
Correct |
1166 ms |
2836 KB |
Output is correct |
18 |
Correct |
2350 ms |
3576 KB |
Output is correct |
19 |
Correct |
2056 ms |
3856 KB |
Output is correct |
20 |
Correct |
1987 ms |
3064 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1714 ms |
6944 KB |
Output is correct |
13 |
Correct |
1335 ms |
7236 KB |
Output is correct |
14 |
Correct |
1758 ms |
3916 KB |
Output is correct |
15 |
Correct |
1903 ms |
3728 KB |
Output is correct |
16 |
Correct |
1033 ms |
3100 KB |
Output is correct |
17 |
Correct |
1768 ms |
3832 KB |
Output is correct |
18 |
Correct |
1740 ms |
3448 KB |
Output is correct |
19 |
Correct |
2475 ms |
6520 KB |
Output is correct |
20 |
Correct |
3880 ms |
2808 KB |
Output is correct |
21 |
Correct |
928 ms |
1008 KB |
Output is correct |
22 |
Correct |
3835 ms |
2876 KB |
Output is correct |
23 |
Correct |
1316 ms |
3312 KB |
Output is correct |
24 |
Correct |
1171 ms |
2808 KB |
Output is correct |
25 |
Correct |
2341 ms |
3764 KB |
Output is correct |
26 |
Correct |
2031 ms |
3708 KB |
Output is correct |
27 |
Correct |
1952 ms |
3192 KB |
Output is correct |
28 |
Correct |
1330 ms |
3664 KB |
Output is correct |
29 |
Correct |
2416 ms |
6220 KB |
Output is correct |
30 |
Correct |
3881 ms |
3328 KB |
Output is correct |
31 |
Correct |
3456 ms |
3116 KB |
Output is correct |
32 |
Correct |
925 ms |
1144 KB |
Output is correct |
33 |
Correct |
1029 ms |
1016 KB |
Output is correct |
34 |
Correct |
1340 ms |
3436 KB |
Output is correct |
35 |
Correct |
1229 ms |
2776 KB |
Output is correct |
36 |
Correct |
2416 ms |
3764 KB |
Output is correct |
37 |
Correct |
2025 ms |
3980 KB |
Output is correct |
38 |
Correct |
1988 ms |
3224 KB |
Output is correct |
39 |
Correct |
1653 ms |
3724 KB |
Output is correct |
40 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1693 ms |
7116 KB |
Output is correct |
13 |
Correct |
1192 ms |
7304 KB |
Output is correct |
14 |
Correct |
1655 ms |
4000 KB |
Output is correct |
15 |
Correct |
1770 ms |
4088 KB |
Output is correct |
16 |
Correct |
893 ms |
3320 KB |
Output is correct |
17 |
Correct |
1725 ms |
3964 KB |
Output is correct |
18 |
Correct |
1661 ms |
3504 KB |
Output is correct |
19 |
Correct |
2383 ms |
6564 KB |
Output is correct |
20 |
Correct |
3797 ms |
2916 KB |
Output is correct |
21 |
Correct |
917 ms |
1144 KB |
Output is correct |
22 |
Correct |
3833 ms |
3152 KB |
Output is correct |
23 |
Correct |
1279 ms |
3320 KB |
Output is correct |
24 |
Correct |
1181 ms |
3064 KB |
Output is correct |
25 |
Correct |
2389 ms |
3844 KB |
Output is correct |
26 |
Correct |
2021 ms |
3748 KB |
Output is correct |
27 |
Correct |
1984 ms |
3192 KB |
Output is correct |
28 |
Correct |
1349 ms |
3860 KB |
Output is correct |
29 |
Correct |
2462 ms |
6252 KB |
Output is correct |
30 |
Correct |
3947 ms |
3184 KB |
Output is correct |
31 |
Correct |
3493 ms |
3156 KB |
Output is correct |
32 |
Correct |
926 ms |
976 KB |
Output is correct |
33 |
Correct |
1097 ms |
1144 KB |
Output is correct |
34 |
Correct |
1410 ms |
3548 KB |
Output is correct |
35 |
Correct |
1329 ms |
3140 KB |
Output is correct |
36 |
Correct |
2576 ms |
4048 KB |
Output is correct |
37 |
Correct |
2092 ms |
5240 KB |
Output is correct |
38 |
Correct |
2027 ms |
4608 KB |
Output is correct |
39 |
Correct |
2883 ms |
11952 KB |
Output is correct |
40 |
Correct |
4797 ms |
13756 KB |
Output is correct |
41 |
Correct |
7651 ms |
11116 KB |
Output is correct |
42 |
Correct |
6137 ms |
10320 KB |
Output is correct |
43 |
Correct |
2716 ms |
10956 KB |
Output is correct |
44 |
Correct |
1970 ms |
6392 KB |
Output is correct |
45 |
Correct |
1684 ms |
8900 KB |
Output is correct |
46 |
Correct |
4006 ms |
12072 KB |
Output is correct |
47 |
Correct |
3875 ms |
11740 KB |
Output is correct |
48 |
Correct |
3678 ms |
11360 KB |
Output is correct |
49 |
Correct |
1 ms |
384 KB |
Output is correct |