답안 #363870

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
363870 2021-02-07T12:12:54 Z Gareton 게임 (IOI13_game) C++14
100 / 100
10341 ms 132368 KB
#include "game.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define orset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#pragma GCC optimize("O3")
// #pragma GCC target("sse", "sse2", "sse3", "sse4")
//#pragma GCC target("avx2")
#define int long long
#define ll long long
#define pii pair<int, int>
#define x first
#define y second
#define all(a) (a.begin()), (a.end())
#define gsz(x) ((int)x.size())
#define endl "\n"
#define LOCAL
#ifdef LOCAL
#define dbg(x) cerr << #x << ":" << (x) << endl
#define print(x) cerr << (x) << endl
#else
#define dbg(x) 0
#define print(x) 0
#endif

using namespace std;
using namespace __gnu_pbds;

const int N = 2e6 + 10;
const int B = 340;
const ll inf = 1e18 + 10;
const ll mod = 1e9 + 7;

mt19937 rnd(4);//chrono::high_resolution_clock::now().time_since_epoch().count());

long long gcd2(long long X, long long Y) {
    assert(X >= 0 && Y >= 0);

    long long tmp;
    while (X != Y && Y != 0) {
        tmp = X;
        X = Y;
        Y = tmp % Y;
    }
    return X;
}

struct nodey{
    int x, y, prior = rnd();
    int val, gcd;
    int l = -1, r = -1;
};

struct nodex{
    int l = -1, r = -1;
    int rooty = -1;
};

nodex tx[N];
nodey ty[N];
int n, m;
int topx = 0, topy = 0;
int rootx = -1;

int getgcd(int v)
{
    return v == -1 ? 0 : ty[v].gcd;
}

void updy(int v)
{
    if(v == -1) return;

    ty[v].gcd = gcd2(gcd2(ty[v].val, getgcd(ty[v].l)), getgcd(ty[v].r));
}



int mergey(int l, int r)
{
    if(l == -1) return r;
    if(r == -1) return l;

    if(ty[l].prior > ty[r].prior)
    {
        ty[l].r = mergey(ty[l].r, r);

        updy(l);

        return l;
    }
    else
    {
        ty[r].l = mergey(l, ty[r].l);

        updy(r);

        return r;
    }
}

pii splity(int v, pii k)
{
    if(v == -1) return {-1, -1};

    if(make_pair(ty[v].y, ty[v].x) > k)
    {
        pii p = splity(ty[v].l, k);

        ty[v].l = p.y;
        updy(v);

        return {p.x, v};
    }
    else
    {
        pii p = splity(ty[v].r, k);

        ty[v].r = p.x;
        updy(v);

        return {v, p.y};
    }
}

int createx()
{
    int v = topx++;

    return v;
}

map<pii, int> mp;

int gety(int &v, int ly, int ry)
{
    pii p1 = splity(v, {ly - 1, inf});
    pii p2 = splity(p1.y, {ry, inf});

    int val = getgcd(p2.x);

    v = mergey(p1.x, mergey(p2.x, p2.y));

    return val;
}

int getx(int tl, int tr, int v, int lx, int rx, int ly, int ry)
{
    if(v == -1)
        return 0;

    if(tl > rx || tr < lx)
        return 0;

    if(tl >= lx && tr <= rx)
        return gety(tx[v].rooty, ly, ry);

    int mid = (tl + tr) / 2;

    return gcd2(getx(tl, mid, tx[v].l, lx, rx, ly, ry), getx(mid + 1, tr, tx[v].r, lx, rx, ly, ry));
}

int createy(int x, int y, int val)
{
    int v = topy++;

    ty[v].x = x;
    ty[v].y = y;
    ty[v].val = ty[v].gcd = val;

    return v;
}

void changey(int &v, int x, int y, int val)
{
    pii p1 = splity(v, {y, x - 1});
    pii p2 = splity(p1.y, {y, x});

    v = mergey(p1.x, mergey(createy(x, y, val), p2.y));
}

int changex(int tl, int tr, int v, int x, int y, int val)
{
    if(tl > x || tr < x)
        return v;

    if(v == -1)
        v = createx();

    changey(tx[v].rooty, x, y, val);

    if(tl == tr)
        return v;

    int mid = (tl + tr) / 2;

    tx[v].l = changex(tl, mid, tx[v].l, x, y, val);
    tx[v].r = changex(mid + 1, tr, tx[v].r, x, y, val);

    return v; 
}

void init(int32_t n, int32_t m) 
{
    ::n = n;
    ::m = m;
}

void update(int32_t x, int32_t y, ll val) 
{
    rootx = changex(0, (ll)n - 1, rootx, x, y, val);
}

long long calculate(int32_t x1, int32_t y1, int32_t x2, int32_t y2) 
{
    return getx(0, (ll)n - 1, rootx, x1, x2, y1, y2);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 109932 KB Output is correct
2 Correct 75 ms 110060 KB Output is correct
3 Correct 76 ms 109932 KB Output is correct
4 Correct 75 ms 109932 KB Output is correct
5 Correct 76 ms 109932 KB Output is correct
6 Correct 75 ms 109932 KB Output is correct
7 Correct 75 ms 109932 KB Output is correct
8 Correct 73 ms 109932 KB Output is correct
9 Correct 73 ms 110060 KB Output is correct
10 Correct 74 ms 109932 KB Output is correct
11 Correct 73 ms 109932 KB Output is correct
12 Correct 74 ms 109932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 110096 KB Output is correct
2 Correct 76 ms 109932 KB Output is correct
3 Correct 75 ms 109932 KB Output is correct
4 Correct 1227 ms 118636 KB Output is correct
5 Correct 600 ms 118508 KB Output is correct
6 Correct 1563 ms 116264 KB Output is correct
7 Correct 1753 ms 115692 KB Output is correct
8 Correct 1210 ms 115820 KB Output is correct
9 Correct 1714 ms 115708 KB Output is correct
10 Correct 1519 ms 115344 KB Output is correct
11 Correct 73 ms 110060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 109912 KB Output is correct
2 Correct 73 ms 109932 KB Output is correct
3 Correct 75 ms 110060 KB Output is correct
4 Correct 74 ms 109932 KB Output is correct
5 Correct 73 ms 109932 KB Output is correct
6 Correct 75 ms 109932 KB Output is correct
7 Correct 74 ms 110064 KB Output is correct
8 Correct 72 ms 109932 KB Output is correct
9 Correct 74 ms 109932 KB Output is correct
10 Correct 74 ms 110060 KB Output is correct
11 Correct 75 ms 109964 KB Output is correct
12 Correct 2066 ms 118516 KB Output is correct
13 Correct 4963 ms 114944 KB Output is correct
14 Correct 828 ms 115308 KB Output is correct
15 Correct 5533 ms 115436 KB Output is correct
16 Correct 548 ms 115052 KB Output is correct
17 Correct 2392 ms 116332 KB Output is correct
18 Correct 4645 ms 116716 KB Output is correct
19 Correct 3684 ms 116968 KB Output is correct
20 Correct 3596 ms 116240 KB Output is correct
21 Correct 71 ms 109932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 109932 KB Output is correct
2 Correct 73 ms 110060 KB Output is correct
3 Correct 72 ms 109932 KB Output is correct
4 Correct 74 ms 109932 KB Output is correct
5 Correct 71 ms 109964 KB Output is correct
6 Correct 72 ms 110048 KB Output is correct
7 Correct 72 ms 109932 KB Output is correct
8 Correct 71 ms 109932 KB Output is correct
9 Correct 72 ms 109932 KB Output is correct
10 Correct 71 ms 109944 KB Output is correct
11 Correct 71 ms 109932 KB Output is correct
12 Correct 1219 ms 118764 KB Output is correct
13 Correct 589 ms 118380 KB Output is correct
14 Correct 1515 ms 115820 KB Output is correct
15 Correct 1750 ms 115476 KB Output is correct
16 Correct 1193 ms 116204 KB Output is correct
17 Correct 1685 ms 115704 KB Output is correct
18 Correct 1499 ms 115564 KB Output is correct
19 Correct 2067 ms 118180 KB Output is correct
20 Correct 5014 ms 114984 KB Output is correct
21 Correct 829 ms 115308 KB Output is correct
22 Correct 5449 ms 115464 KB Output is correct
23 Correct 522 ms 114924 KB Output is correct
24 Correct 2379 ms 116204 KB Output is correct
25 Correct 4630 ms 116768 KB Output is correct
26 Correct 3695 ms 116576 KB Output is correct
27 Correct 3596 ms 116076 KB Output is correct
28 Correct 1377 ms 125420 KB Output is correct
29 Correct 2926 ms 128108 KB Output is correct
30 Correct 7446 ms 119752 KB Output is correct
31 Correct 6373 ms 119424 KB Output is correct
32 Correct 1165 ms 120044 KB Output is correct
33 Correct 1670 ms 119916 KB Output is correct
34 Correct 525 ms 121656 KB Output is correct
35 Correct 2818 ms 123244 KB Output is correct
36 Correct 5527 ms 125720 KB Output is correct
37 Correct 4299 ms 126128 KB Output is correct
38 Correct 4407 ms 125520 KB Output is correct
39 Correct 3688 ms 124860 KB Output is correct
40 Correct 70 ms 109932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 109932 KB Output is correct
2 Correct 75 ms 109932 KB Output is correct
3 Correct 73 ms 110060 KB Output is correct
4 Correct 73 ms 109932 KB Output is correct
5 Correct 73 ms 109932 KB Output is correct
6 Correct 71 ms 109932 KB Output is correct
7 Correct 73 ms 109932 KB Output is correct
8 Correct 75 ms 109932 KB Output is correct
9 Correct 71 ms 109932 KB Output is correct
10 Correct 71 ms 109932 KB Output is correct
11 Correct 72 ms 109932 KB Output is correct
12 Correct 1218 ms 118748 KB Output is correct
13 Correct 587 ms 118272 KB Output is correct
14 Correct 1539 ms 115820 KB Output is correct
15 Correct 1757 ms 115692 KB Output is correct
16 Correct 1188 ms 115972 KB Output is correct
17 Correct 1691 ms 115564 KB Output is correct
18 Correct 1496 ms 115436 KB Output is correct
19 Correct 2052 ms 118184 KB Output is correct
20 Correct 4878 ms 114848 KB Output is correct
21 Correct 830 ms 115180 KB Output is correct
22 Correct 5398 ms 115624 KB Output is correct
23 Correct 528 ms 115052 KB Output is correct
24 Correct 2392 ms 116588 KB Output is correct
25 Correct 4557 ms 116500 KB Output is correct
26 Correct 3638 ms 116716 KB Output is correct
27 Correct 3608 ms 116332 KB Output is correct
28 Correct 1326 ms 125472 KB Output is correct
29 Correct 2760 ms 128140 KB Output is correct
30 Correct 6885 ms 119916 KB Output is correct
31 Correct 6117 ms 119668 KB Output is correct
32 Correct 1164 ms 119916 KB Output is correct
33 Correct 1629 ms 119788 KB Output is correct
34 Correct 520 ms 121580 KB Output is correct
35 Correct 2768 ms 123652 KB Output is correct
36 Correct 5453 ms 125872 KB Output is correct
37 Correct 4220 ms 125964 KB Output is correct
38 Correct 4316 ms 125604 KB Output is correct
39 Correct 1775 ms 129900 KB Output is correct
40 Correct 4449 ms 132368 KB Output is correct
41 Correct 10341 ms 122748 KB Output is correct
42 Correct 9399 ms 121492 KB Output is correct
43 Correct 916 ms 126572 KB Output is correct
44 Correct 1967 ms 120224 KB Output is correct
45 Correct 3527 ms 125352 KB Output is correct
46 Correct 6797 ms 130812 KB Output is correct
47 Correct 6851 ms 130560 KB Output is correct
48 Correct 6836 ms 130416 KB Output is correct
49 Correct 73 ms 109932 KB Output is correct