# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
151681 |
2019-09-04T06:32:14 Z |
qkxwsm |
Game (IOI13_game) |
C++14 |
|
13000 ms |
58088 KB |
#include <bits/stdc++.h>
#include "game.h"
using namespace std;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
#define y1 qwertyuiop
#define y2 asdfghjkl
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define INF 1000000007
#define LLINF 2696969696969696969
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
int N, M;
ll gcd(ll a, ll b)
{
return (b == 0 ? a : gcd(b, a % b));
}
struct node
{
pii idx;
int pri;
ll cur, stor;
node *ch[2];
node(pii x, ll v)
{
idx = x; pri = (rand() << 15 + rand()) % INF;
cur = v; stor = v;
ch[0] = nullptr; ch[1] = nullptr;
}
};
void pull(node *t)
{
if (!t) return;
t -> stor = t -> cur;
if (t -> ch[0]) t -> stor = gcd(t -> stor, t -> ch[0] -> stor);
if (t -> ch[1]) t -> stor = gcd(t -> stor, t -> ch[1] -> stor);
return;
}
typedef pair<node*, node*> pnn;
node *merge(node *l, node *r)
{
if (!l) return r;
if (!r) return l;
if (l -> pri > r -> pri)
{
l -> ch[1] = merge(l -> ch[1], r);
pull(l); return l;
}
else
{
r -> ch[0] = merge(l, r -> ch[0]);
pull(r); return r;
}
}
pnn split(node *t, pii v)
{
if (!t) return {t, t};
pii cur = t -> idx;
if (v > cur)
{
pnn p = split(t -> ch[1], v);
t -> ch[1] = p.fi; pull(t);
return {t, p.se};
}
else
{
pnn p = split(t -> ch[0], v);
t -> ch[0] = p.se; pull(t);
return {p.fi, t};
}
}
void inorder(node *t)
{
if (!t) return;
inorder(t -> ch[0]);
cerr << t -> idx.fi << ',' << t -> cur << ' ';
inorder(t -> ch[1]);
}
struct Node
{
node *root;
Node *ch[2];
Node()
{
root = nullptr;
ch[0] = nullptr;
ch[1] = nullptr;
}
};
Node *root;
Node* upd(Node *t, int L, int R, int a, int y, ll v)
{
if (!t) t = new Node();
pnn p = split(t -> root, {y, a}), p1 = split(p.se, {y, a + 1});
t -> root = merge(p.fi, merge(new node({y, a}, v), p1.se));
if (L != R)
{
int mid = (L + R) >> 1;
if (a <= mid)
{
t -> ch[0] = upd(t -> ch[0], L, mid, a, y, v);
}
else
{
t -> ch[1] = upd(t -> ch[1], mid + 1, R, a, y, v);
}
}
return t;
}
ll qry(Node *t, int L, int R, int a, int b, int y1, int y2)
{
if (!t) return 0;
if (a <= L && R <= b)
{
pnn p = split(t -> root, {y1, 0}), p1 = split(p.se, {y2 + 1, 0});
ll res = (p1.fi ? p1.fi -> stor : 0);
t -> root = merge(p.fi, merge(p1.fi, p1.se));
return res;
}
int mid = (L + R) >> 1;
if (b <= mid) return qry(t -> ch[0], L, mid, a, b, y1, y2);
if (mid < a) return qry(t -> ch[1], mid + 1, R, a, b, y1, y2);
return gcd(qry(t -> ch[0], L, mid, a, b, y1, y2), qry(t -> ch[1], mid + 1, R, a, b, y1, y2));
}
void init(int n, int m)
{
N = n; M = m;
srand(42);
}
void update(int x, int y, ll v)
{
root = upd(root, 0, N - 1, x, y, v);
}
ll calculate(int x1, int y1, int x2, int y2)
{
return qry(root, 0, N - 1, x1, x2, y1, y2);
}
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;
^~~
game.cpp: In constructor 'node::node(pii, ll)':
game.cpp:56:32: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
idx = x; pri = (rand() << 15 + rand()) % INF;
~~~^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
296 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
1969 ms |
9540 KB |
Output is correct |
5 |
Correct |
731 ms |
9792 KB |
Output is correct |
6 |
Correct |
2535 ms |
6732 KB |
Output is correct |
7 |
Correct |
2960 ms |
6384 KB |
Output is correct |
8 |
Correct |
1968 ms |
5692 KB |
Output is correct |
9 |
Correct |
2803 ms |
6548 KB |
Output is correct |
10 |
Correct |
2743 ms |
6240 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
4 ms |
504 KB |
Output is correct |
7 |
Correct |
3 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3157 ms |
13848 KB |
Output is correct |
13 |
Correct |
8376 ms |
10672 KB |
Output is correct |
14 |
Correct |
1236 ms |
10952 KB |
Output is correct |
15 |
Correct |
9094 ms |
11320 KB |
Output is correct |
16 |
Correct |
1055 ms |
11172 KB |
Output is correct |
17 |
Correct |
4264 ms |
7876 KB |
Output is correct |
18 |
Correct |
7853 ms |
11668 KB |
Output is correct |
19 |
Correct |
6481 ms |
11808 KB |
Output is correct |
20 |
Correct |
7229 ms |
11128 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
1946 ms |
9624 KB |
Output is correct |
13 |
Correct |
735 ms |
9956 KB |
Output is correct |
14 |
Correct |
2791 ms |
6720 KB |
Output is correct |
15 |
Correct |
3032 ms |
6416 KB |
Output is correct |
16 |
Correct |
2037 ms |
5632 KB |
Output is correct |
17 |
Correct |
2866 ms |
6476 KB |
Output is correct |
18 |
Correct |
2748 ms |
6152 KB |
Output is correct |
19 |
Correct |
3211 ms |
13828 KB |
Output is correct |
20 |
Correct |
8373 ms |
10648 KB |
Output is correct |
21 |
Correct |
1218 ms |
10868 KB |
Output is correct |
22 |
Correct |
9097 ms |
11276 KB |
Output is correct |
23 |
Correct |
997 ms |
11084 KB |
Output is correct |
24 |
Correct |
4226 ms |
7788 KB |
Output is correct |
25 |
Correct |
7894 ms |
11580 KB |
Output is correct |
26 |
Correct |
6497 ms |
11628 KB |
Output is correct |
27 |
Correct |
7175 ms |
11072 KB |
Output is correct |
28 |
Correct |
2058 ms |
28120 KB |
Output is correct |
29 |
Correct |
4009 ms |
31168 KB |
Output is correct |
30 |
Correct |
10992 ms |
25736 KB |
Output is correct |
31 |
Correct |
9504 ms |
25148 KB |
Output is correct |
32 |
Correct |
1708 ms |
22592 KB |
Output is correct |
33 |
Correct |
2654 ms |
22520 KB |
Output is correct |
34 |
Correct |
983 ms |
28160 KB |
Output is correct |
35 |
Correct |
4740 ms |
16248 KB |
Output is correct |
36 |
Correct |
8866 ms |
28576 KB |
Output is correct |
37 |
Correct |
7070 ms |
28452 KB |
Output is correct |
38 |
Correct |
8053 ms |
28016 KB |
Output is correct |
39 |
Correct |
6007 ms |
22616 KB |
Output is correct |
40 |
Correct |
2 ms |
508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
1952 ms |
8912 KB |
Output is correct |
13 |
Correct |
748 ms |
9196 KB |
Output is correct |
14 |
Correct |
2563 ms |
5944 KB |
Output is correct |
15 |
Correct |
3125 ms |
5836 KB |
Output is correct |
16 |
Correct |
1945 ms |
5072 KB |
Output is correct |
17 |
Correct |
2864 ms |
5756 KB |
Output is correct |
18 |
Correct |
2705 ms |
5480 KB |
Output is correct |
19 |
Correct |
3124 ms |
13012 KB |
Output is correct |
20 |
Correct |
8348 ms |
9872 KB |
Output is correct |
21 |
Correct |
1245 ms |
10248 KB |
Output is correct |
22 |
Correct |
9041 ms |
10380 KB |
Output is correct |
23 |
Correct |
1037 ms |
10456 KB |
Output is correct |
24 |
Correct |
4300 ms |
7192 KB |
Output is correct |
25 |
Correct |
7686 ms |
10740 KB |
Output is correct |
26 |
Correct |
6461 ms |
10804 KB |
Output is correct |
27 |
Correct |
7481 ms |
10264 KB |
Output is correct |
28 |
Correct |
2110 ms |
27456 KB |
Output is correct |
29 |
Correct |
4024 ms |
30428 KB |
Output is correct |
30 |
Correct |
10835 ms |
24756 KB |
Output is correct |
31 |
Correct |
9443 ms |
24292 KB |
Output is correct |
32 |
Correct |
1721 ms |
21708 KB |
Output is correct |
33 |
Correct |
2619 ms |
21660 KB |
Output is correct |
34 |
Correct |
969 ms |
27312 KB |
Output is correct |
35 |
Correct |
4750 ms |
15420 KB |
Output is correct |
36 |
Correct |
8613 ms |
27580 KB |
Output is correct |
37 |
Correct |
6966 ms |
27736 KB |
Output is correct |
38 |
Correct |
8241 ms |
27124 KB |
Output is correct |
39 |
Correct |
2734 ms |
55748 KB |
Output is correct |
40 |
Correct |
6460 ms |
58088 KB |
Output is correct |
41 |
Execution timed out |
13087 ms |
49076 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |