#include "game.h"
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <algorithm>
#include <random>
#include <ctime>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define pb push_back
#define _1 first
#define _2 second
#define INF 1145141919
#define MOD 1000000007
inline long long gcd(long long X, long long Y) {
long long tmp;
while (X != Y && Y != 0) {
tmp = X;
X = Y;
Y = tmp % Y;
}
return X;
}
mt19937 mt_rand(time(NULL));
const int MAX_N = 1000000001;
struct Treap {
int p;
long long key, key_min, key_max;
long long val, seg;
Treap *ch[2];
Treap(long long k, long long v) : p(mt_rand()), key(k), key_min(k), key_max(k), val(v), seg(v) {
ch[0] = ch[1] = NULL;
}
Treap() {}
};
// inline long long seg(Treap *t) { return t ? t->seg : 0; }
inline Treap *update(Treap *t) {
if (t == NULL) return t;
t->seg = t->val;
t->key_min = t->key;
t->key_max = t->key;
rep(c, 2) if (t->ch[c]) {
t->seg = gcd(t->seg, t->ch[c]->seg);
t->key_min = min(t->key_min, t->ch[c]->key_min);
t->key_max = max(t->key_max, t->ch[c]->key_max);
}
return t;
}
Treap *merge(Treap *l, Treap *r) {
if (l == NULL) return r;
if (r == NULL) return l;
if (l->p > r->p) {
l->ch[1] = merge(l->ch[1], r);
return update(l);
}
else {
r->ch[0] = merge(l, r->ch[0]);
return update(r);
}
}
// k=lower_bound(val), [0, k) | [k, n)
pair<Treap*, Treap*> splitByValue(Treap *t, long long val) {
if (t == NULL) return {NULL, NULL};
if (val <= t->key) {
auto s = splitByValue(t->ch[0], val);
t->ch[0] = s._2;
return { s._1, update(t) };
}
else {
auto s = splitByValue(t->ch[1], val);
t->ch[1] = s._1;
return { update(t), s._2 };
}
}
void print(Treap *t) {
if (t == NULL) return;
print(t->ch[0]);
cout << t->key<<"->"<<t->val<<"\n";
print(t->ch[1]);
}
long long g;
inline void add_gcd(long long x) { g = gcd(g, x); }
void range_seg(Treap *t, long long a, long long b) {
if (t == NULL) return;
long long l = t->key_min, r = t->key_max+1;
if (b <= l || r <= a) return;
if (a <= l && r <= b) {
add_gcd(t->seg);
return;
}
if (a <= t->key && t->key < b) add_gcd(t->val);
range_seg(t->ch[0], a, b);
range_seg(t->ch[1], a, b);
}
int V = 0;
Treap pool[700000];
inline Treap *alloc(long long key, long long val) {
return &(pool[V++] = Treap(key, val));
}
struct TMap {
Treap *treap;
TMap() : treap(NULL) {}
void update(long long key, long long val) {
auto s = splitByValue(treap, key);
auto s2 = splitByValue(s._2, key+1);
if (s2._1 == NULL) s2._1 = alloc(key, val);
else s2._1->val = s2._1->seg = val;
treap = merge(s._1, merge(s2._1, s2._2));
}
void gcd(long long l, long long r) { range_seg(treap, l, r); }
};
struct SegTree {
SegTree *lch, *rch;
TMap mp;
SegTree() : lch(NULL), rch(NULL) {}
void update(int x, int y, long long v, int l=0, int r=MAX_N) {
mp.update(1LL*MAX_N*y+x, v);
if (r-l == 1) return;
if (x < (l+r)/2) {
if (lch == NULL) lch = new SegTree();
lch->update(x, y, v, l, (l+r)/2);
}
else {
if (rch == NULL) rch = new SegTree();
rch->update(x, y, v, (l+r)/2, r);
}
}
void query(int a, int b, int ql, int qr, int l=0, int r=MAX_N) {
if (b <= l || r <= a) return;
if (a <= l && r <= b) return mp.gcd(1LL*MAX_N*ql, 1LL*MAX_N*qr);
if (lch) lch->query(a, b, ql, qr, l, (l+r)/2);
if (rch) rch->query(a, b, ql, qr, (l+r)/2, r);
}
};
SegTree root;
void init(int R, int C) {}
void update(int P, int Q, long long K) {
root.update(P, Q, K);
}
long long calculate(int P, int Q, int U, int V) {
g = 0;
root.query(P, U+1, Q, V+1);
return g;
}
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 |
0 ms |
45772 KB |
Output is correct |
2 |
Correct |
6 ms |
45772 KB |
Output is correct |
3 |
Correct |
6 ms |
45772 KB |
Output is correct |
4 |
Correct |
0 ms |
45772 KB |
Output is correct |
5 |
Correct |
0 ms |
45772 KB |
Output is correct |
6 |
Correct |
6 ms |
45772 KB |
Output is correct |
7 |
Correct |
0 ms |
45772 KB |
Output is correct |
8 |
Correct |
0 ms |
45772 KB |
Output is correct |
9 |
Correct |
3 ms |
45772 KB |
Output is correct |
10 |
Correct |
0 ms |
45772 KB |
Output is correct |
11 |
Correct |
0 ms |
45772 KB |
Output is correct |
12 |
Correct |
0 ms |
45772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
45772 KB |
Output is correct |
2 |
Correct |
0 ms |
45772 KB |
Output is correct |
3 |
Correct |
0 ms |
45772 KB |
Output is correct |
4 |
Correct |
2196 ms |
45772 KB |
Output is correct |
5 |
Correct |
1479 ms |
45772 KB |
Output is correct |
6 |
Correct |
3256 ms |
45772 KB |
Output is correct |
7 |
Correct |
3606 ms |
45772 KB |
Output is correct |
8 |
Correct |
1873 ms |
45772 KB |
Output is correct |
9 |
Correct |
3823 ms |
45772 KB |
Output is correct |
10 |
Correct |
3123 ms |
45772 KB |
Output is correct |
11 |
Correct |
0 ms |
45772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
45772 KB |
Output is correct |
2 |
Correct |
6 ms |
45772 KB |
Output is correct |
3 |
Correct |
6 ms |
45772 KB |
Output is correct |
4 |
Correct |
0 ms |
45772 KB |
Output is correct |
5 |
Correct |
0 ms |
45772 KB |
Output is correct |
6 |
Correct |
6 ms |
45772 KB |
Output is correct |
7 |
Correct |
0 ms |
45772 KB |
Output is correct |
8 |
Correct |
0 ms |
45772 KB |
Output is correct |
9 |
Correct |
3 ms |
45772 KB |
Output is correct |
10 |
Correct |
3 ms |
45772 KB |
Output is correct |
11 |
Correct |
0 ms |
45772 KB |
Output is correct |
12 |
Correct |
2719 ms |
45904 KB |
Output is correct |
13 |
Correct |
4906 ms |
45904 KB |
Output is correct |
14 |
Correct |
1223 ms |
45772 KB |
Output is correct |
15 |
Correct |
4776 ms |
45904 KB |
Output is correct |
16 |
Correct |
1576 ms |
45904 KB |
Output is correct |
17 |
Correct |
2156 ms |
45904 KB |
Output is correct |
18 |
Correct |
5686 ms |
45904 KB |
Output is correct |
19 |
Correct |
4499 ms |
45904 KB |
Output is correct |
20 |
Correct |
3969 ms |
45904 KB |
Output is correct |
21 |
Correct |
0 ms |
45772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
45772 KB |
Output is correct |
2 |
Correct |
6 ms |
45772 KB |
Output is correct |
3 |
Correct |
6 ms |
45772 KB |
Output is correct |
4 |
Correct |
0 ms |
45772 KB |
Output is correct |
5 |
Correct |
0 ms |
45772 KB |
Output is correct |
6 |
Correct |
6 ms |
45772 KB |
Output is correct |
7 |
Correct |
0 ms |
45772 KB |
Output is correct |
8 |
Correct |
0 ms |
45772 KB |
Output is correct |
9 |
Correct |
6 ms |
45772 KB |
Output is correct |
10 |
Correct |
0 ms |
45772 KB |
Output is correct |
11 |
Correct |
0 ms |
45772 KB |
Output is correct |
12 |
Correct |
2353 ms |
45772 KB |
Output is correct |
13 |
Correct |
1353 ms |
45772 KB |
Output is correct |
14 |
Correct |
3309 ms |
45772 KB |
Output is correct |
15 |
Correct |
3703 ms |
45772 KB |
Output is correct |
16 |
Correct |
1703 ms |
45772 KB |
Output is correct |
17 |
Correct |
3586 ms |
45772 KB |
Output is correct |
18 |
Correct |
3076 ms |
45772 KB |
Output is correct |
19 |
Correct |
2829 ms |
45904 KB |
Output is correct |
20 |
Correct |
4989 ms |
45904 KB |
Output is correct |
21 |
Correct |
1243 ms |
45772 KB |
Output is correct |
22 |
Correct |
4736 ms |
45904 KB |
Output is correct |
23 |
Correct |
1933 ms |
45904 KB |
Output is correct |
24 |
Correct |
2209 ms |
45904 KB |
Output is correct |
25 |
Correct |
4953 ms |
45904 KB |
Output is correct |
26 |
Correct |
4599 ms |
45904 KB |
Output is correct |
27 |
Correct |
4029 ms |
45904 KB |
Output is correct |
28 |
Correct |
936 ms |
51316 KB |
Output is correct |
29 |
Correct |
2773 ms |
51316 KB |
Output is correct |
30 |
Correct |
4783 ms |
48808 KB |
Output is correct |
31 |
Correct |
4556 ms |
48148 KB |
Output is correct |
32 |
Correct |
1373 ms |
45772 KB |
Output is correct |
33 |
Correct |
1413 ms |
45904 KB |
Output is correct |
34 |
Correct |
799 ms |
51316 KB |
Output is correct |
35 |
Correct |
1933 ms |
48676 KB |
Output is correct |
36 |
Correct |
4566 ms |
51316 KB |
Output is correct |
37 |
Correct |
4013 ms |
51316 KB |
Output is correct |
38 |
Correct |
3109 ms |
51316 KB |
Output is correct |
39 |
Correct |
2553 ms |
50128 KB |
Output is correct |
40 |
Correct |
0 ms |
45772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
45772 KB |
Output is correct |
2 |
Correct |
6 ms |
45772 KB |
Output is correct |
3 |
Correct |
6 ms |
45772 KB |
Output is correct |
4 |
Correct |
0 ms |
45772 KB |
Output is correct |
5 |
Correct |
0 ms |
45772 KB |
Output is correct |
6 |
Correct |
6 ms |
45772 KB |
Output is correct |
7 |
Correct |
0 ms |
45772 KB |
Output is correct |
8 |
Correct |
0 ms |
45772 KB |
Output is correct |
9 |
Correct |
6 ms |
45772 KB |
Output is correct |
10 |
Correct |
0 ms |
45772 KB |
Output is correct |
11 |
Correct |
0 ms |
45772 KB |
Output is correct |
12 |
Correct |
2319 ms |
45772 KB |
Output is correct |
13 |
Correct |
1609 ms |
45772 KB |
Output is correct |
14 |
Correct |
3393 ms |
45772 KB |
Output is correct |
15 |
Correct |
3689 ms |
45772 KB |
Output is correct |
16 |
Correct |
1609 ms |
45772 KB |
Output is correct |
17 |
Correct |
3676 ms |
45772 KB |
Output is correct |
18 |
Correct |
2799 ms |
45772 KB |
Output is correct |
19 |
Correct |
2646 ms |
45904 KB |
Output is correct |
20 |
Correct |
4569 ms |
45904 KB |
Output is correct |
21 |
Correct |
1193 ms |
45772 KB |
Output is correct |
22 |
Correct |
4876 ms |
45904 KB |
Output is correct |
23 |
Correct |
1873 ms |
45904 KB |
Output is correct |
24 |
Correct |
2409 ms |
45904 KB |
Output is correct |
25 |
Correct |
5569 ms |
45904 KB |
Output is correct |
26 |
Correct |
4526 ms |
45904 KB |
Output is correct |
27 |
Correct |
4119 ms |
45904 KB |
Output is correct |
28 |
Correct |
943 ms |
51316 KB |
Output is correct |
29 |
Correct |
3039 ms |
51316 KB |
Output is correct |
30 |
Correct |
4809 ms |
48808 KB |
Output is correct |
31 |
Correct |
4366 ms |
48148 KB |
Output is correct |
32 |
Correct |
1193 ms |
45772 KB |
Output is correct |
33 |
Correct |
1439 ms |
45904 KB |
Output is correct |
34 |
Correct |
783 ms |
51316 KB |
Output is correct |
35 |
Correct |
1979 ms |
48676 KB |
Output is correct |
36 |
Correct |
4349 ms |
51316 KB |
Output is correct |
37 |
Correct |
3653 ms |
51316 KB |
Output is correct |
38 |
Correct |
3536 ms |
51316 KB |
Output is correct |
39 |
Correct |
1246 ms |
57256 KB |
Output is correct |
40 |
Correct |
5636 ms |
57256 KB |
Output is correct |
41 |
Correct |
8546 ms |
52108 KB |
Output is correct |
42 |
Correct |
7603 ms |
50656 KB |
Output is correct |
43 |
Correct |
1819 ms |
57256 KB |
Output is correct |
44 |
Correct |
2839 ms |
45772 KB |
Output is correct |
45 |
Correct |
2626 ms |
50128 KB |
Output is correct |
46 |
Correct |
6923 ms |
57256 KB |
Output is correct |
47 |
Correct |
6243 ms |
57256 KB |
Output is correct |
48 |
Correct |
5629 ms |
57256 KB |
Output is correct |
49 |
Correct |
0 ms |
45772 KB |
Output is correct |