# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
653890 |
2022-10-28T18:07:19 Z |
vovamr |
Game (IOI13_game) |
C++17 |
|
6997 ms |
67528 KB |
#include "game.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mpp make_pair
#define ve vector
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll inf = 1e18; const int iinf = 1e9;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline bool chmin(T& a, T b) { return (a > b ? a = b, 1 : 0); }
template <typename T> inline bool chmax(T& a, T b) { return (a < b ? a = b, 1 : 0); }
inline ll gcd(const ll &a, const ll &b) { return (!b ? a : gcd(b, a % b)); }
struct node {
node *l = nullptr;
node *r = nullptr;
int p;
pii key;
ll val, g;
node(const pii &key, const ll &x) : key(key), val(x), g(x) { p = rng() % INT_MAX; }
}; typedef node* nd;
inline ll val(nd t) { return !t ? 0 : t->val; }
inline ll g(nd t) { return !t ? 0 : t->g; }
inline void upd(nd t) { if (!t) return; t->g = gcd(gcd(g(t->l), g(t->r)), t->val); }
inline nd mg(nd a, nd b) {
if (!a || !b) return !a ? b : a;
if (a->p > b->p) { a->r = mg(a->r, b); upd(a); return a; }
else { b->l = mg(a, b->l); upd(b); return b; }
}
inline pair<nd,nd> sp(nd t, pii x) {
if (!t) return {nullptr,nullptr};
if (t->key <= x) { auto tt = sp(t->r, x); t->r = tt.fi; upd(t); return {t, tt.se}; }
else { auto tt = sp(t->l, x); t->l = tt.se; upd(t); return {tt.fi, t}; }
}
inline void ins(nd &t, pii pos, ll x) {
auto [t1, t2] = sp(t, mpp(pos.fi, pos.se - 1));
auto [t3, t4] = sp(t2, pos);
t = mg(mg(t1, new node(pos, x)), t4);
}
inline ll get1(nd &t, int l, int r) {
auto [t1, t2] = sp(t, mpp(l - 1, iinf));
auto [t3, t4] = sp(t2, mpp(r, iinf));
ll res = g(t3);
t = mg(t1, mg(t3, t4));
return res;
}
struct Node {
Node *l = nullptr;
Node *r = nullptr;
nd st = nullptr;
Node() {}
}; Node *t = new Node();
inline void upd(Node *&v, int vl, int vr, int x, int y, ll d) {
if (!v) v = new Node();
ins(v->st, mpp(y, x), d);
if (vl == vr) return;
int m = vl + vr >> 1;
if (x <= m) upd(v->l, vl, m, x, y, d);
else upd(v->r, m + 1, vr, x, y, d);
}
inline ll get(Node *v, int vl, int vr, int lx, int rx, int ly, int ry) {
if (lx > rx || !v) return 0ll;
else if (vl == lx && vr == rx) return get1(v->st, ly, ry);
int m = vl + vr >> 1;
return gcd(get(v->l,vl,m,lx,min(rx,m),ly,ry),
get(v->r,m+1,vr,max(lx,m+1),rx,ly,ry));
}
int l1, r1;
void init(int R, int C) {
l1 = 0, r1 = R - 1;
}
void update(int P, int Q, long long K) {
upd(t, l1, r1, P, Q, K);
}
long long calculate(int P, int Q, int U, int V) {
return get(t, l1, r1, P, U, Q, V);
}
Compilation message
game.cpp: In function 'void upd(Node*&, int, int, int, int, long long int)':
game.cpp:71:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
71 | int m = vl + vr >> 1;
| ~~~^~~~
game.cpp: In function 'long long int get(Node*, int, int, int, int, int, int)':
game.cpp:78:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
78 | int m = vl + vr >> 1;
| ~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
788 ms |
7488 KB |
Output is correct |
5 |
Correct |
364 ms |
7940 KB |
Output is correct |
6 |
Correct |
1137 ms |
4680 KB |
Output is correct |
7 |
Correct |
1358 ms |
4624 KB |
Output is correct |
8 |
Correct |
898 ms |
3740 KB |
Output is correct |
9 |
Correct |
1325 ms |
4704 KB |
Output is correct |
10 |
Correct |
1092 ms |
4132 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
300 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1281 ms |
11784 KB |
Output is correct |
13 |
Correct |
3356 ms |
8580 KB |
Output is correct |
14 |
Correct |
589 ms |
8856 KB |
Output is correct |
15 |
Correct |
3669 ms |
9120 KB |
Output is correct |
16 |
Correct |
401 ms |
9060 KB |
Output is correct |
17 |
Correct |
1755 ms |
5816 KB |
Output is correct |
18 |
Correct |
3124 ms |
9656 KB |
Output is correct |
19 |
Correct |
2490 ms |
9740 KB |
Output is correct |
20 |
Correct |
2283 ms |
9076 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
797 ms |
7508 KB |
Output is correct |
13 |
Correct |
391 ms |
7776 KB |
Output is correct |
14 |
Correct |
1114 ms |
4564 KB |
Output is correct |
15 |
Correct |
1325 ms |
4428 KB |
Output is correct |
16 |
Correct |
798 ms |
3852 KB |
Output is correct |
17 |
Correct |
1284 ms |
4356 KB |
Output is correct |
18 |
Correct |
1139 ms |
4052 KB |
Output is correct |
19 |
Correct |
1258 ms |
12000 KB |
Output is correct |
20 |
Correct |
3470 ms |
8512 KB |
Output is correct |
21 |
Correct |
568 ms |
8752 KB |
Output is correct |
22 |
Correct |
3630 ms |
9296 KB |
Output is correct |
23 |
Correct |
371 ms |
9280 KB |
Output is correct |
24 |
Correct |
1715 ms |
6000 KB |
Output is correct |
25 |
Correct |
3381 ms |
9860 KB |
Output is correct |
26 |
Correct |
2527 ms |
9612 KB |
Output is correct |
27 |
Correct |
2408 ms |
9012 KB |
Output is correct |
28 |
Correct |
949 ms |
31896 KB |
Output is correct |
29 |
Correct |
1775 ms |
39044 KB |
Output is correct |
30 |
Correct |
4890 ms |
30232 KB |
Output is correct |
31 |
Correct |
4178 ms |
29704 KB |
Output is correct |
32 |
Correct |
790 ms |
29440 KB |
Output is correct |
33 |
Correct |
1134 ms |
29436 KB |
Output is correct |
34 |
Correct |
470 ms |
32648 KB |
Output is correct |
35 |
Correct |
1924 ms |
23884 KB |
Output is correct |
36 |
Correct |
3683 ms |
37064 KB |
Output is correct |
37 |
Correct |
2859 ms |
37040 KB |
Output is correct |
38 |
Correct |
2761 ms |
36556 KB |
Output is correct |
39 |
Correct |
2388 ms |
30868 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
754 ms |
7292 KB |
Output is correct |
13 |
Correct |
340 ms |
7668 KB |
Output is correct |
14 |
Correct |
1055 ms |
4428 KB |
Output is correct |
15 |
Correct |
1226 ms |
4228 KB |
Output is correct |
16 |
Correct |
814 ms |
3532 KB |
Output is correct |
17 |
Correct |
1207 ms |
4192 KB |
Output is correct |
18 |
Correct |
1029 ms |
3796 KB |
Output is correct |
19 |
Correct |
1231 ms |
11704 KB |
Output is correct |
20 |
Correct |
3398 ms |
8296 KB |
Output is correct |
21 |
Correct |
563 ms |
8564 KB |
Output is correct |
22 |
Correct |
3631 ms |
9032 KB |
Output is correct |
23 |
Correct |
358 ms |
8912 KB |
Output is correct |
24 |
Correct |
1678 ms |
5432 KB |
Output is correct |
25 |
Correct |
2903 ms |
9400 KB |
Output is correct |
26 |
Correct |
2638 ms |
9472 KB |
Output is correct |
27 |
Correct |
2357 ms |
8788 KB |
Output is correct |
28 |
Correct |
886 ms |
31680 KB |
Output is correct |
29 |
Correct |
1708 ms |
38884 KB |
Output is correct |
30 |
Correct |
4947 ms |
30340 KB |
Output is correct |
31 |
Correct |
4014 ms |
29756 KB |
Output is correct |
32 |
Correct |
783 ms |
29340 KB |
Output is correct |
33 |
Correct |
1145 ms |
29560 KB |
Output is correct |
34 |
Correct |
405 ms |
32700 KB |
Output is correct |
35 |
Correct |
1857 ms |
24168 KB |
Output is correct |
36 |
Correct |
3557 ms |
36860 KB |
Output is correct |
37 |
Correct |
2956 ms |
36972 KB |
Output is correct |
38 |
Correct |
2782 ms |
36512 KB |
Output is correct |
39 |
Correct |
1188 ms |
65580 KB |
Output is correct |
40 |
Correct |
2812 ms |
67528 KB |
Output is correct |
41 |
Correct |
6997 ms |
57296 KB |
Output is correct |
42 |
Correct |
6355 ms |
55608 KB |
Output is correct |
43 |
Correct |
692 ms |
62388 KB |
Output is correct |
44 |
Correct |
1326 ms |
53248 KB |
Output is correct |
45 |
Correct |
2386 ms |
31032 KB |
Output is correct |
46 |
Correct |
5010 ms |
66520 KB |
Output is correct |
47 |
Correct |
4958 ms |
66500 KB |
Output is correct |
48 |
Correct |
4554 ms |
65928 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |