답안 #168458

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168458 2019-12-13T07:11:40 Z tri 게임 (IOI13_game) C++14
80 / 100
8934 ms 256000 KB
#include <bits/stdc++.h>
#include "game.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;

#define pb push_back
#define f first
#define s second

namespace debug {
    int DEBUG = false;

    template<class T1, class T2>
    void pr(const pair<T1, T2> &x);

    template<class T, size_t SZ>
    void pr(const array<T, SZ> &x);

    template<class T>
    void pr(const vector<T> &x);

    template<class T>
    void pr(const set<T> &x);

    template<class T1, class T2>
    void pr(const map<T1, T2> &x);

    template<class T>
    void pr(const T &x) { if (DEBUG) cout << x; }

    template<class T, class... Ts>
    void pr(const T &first, const Ts &... rest) { pr(first), pr(rest...); }

    template<class T1, class T2>
    void pr(const pair<T1, T2> &x) { pr("{", x.f, ", ", x.s, "}"); }

    template<class T>
    void prIn(const T &x) {
        pr("{");
        bool fst = 1;
        for (auto &a : x) {
            pr(fst ? "" : ", ", a), fst = 0;
        }
        pr("}");
    }

    template<class T, size_t SZ>
    void pr(const array<T, SZ> &x) { prIn(x); }

    template<class T>
    void pr(const vector<T> &x) { prIn(x); }

    template<class T>
    void pr(const set<T> &x) { prIn(x); }

    template<class T1, class T2>
    void pr(const map<T1, T2> &x) { prIn(x); }

    void ps() { pr("\n"), cout << flush; }

    template<class Arg, class... Args>
    void ps(const Arg &first, const Args &... rest) {
        pr(first, " ");
        ps(rest...);
    }
}
using namespace debug;

const int MAXN = 22000000;

int R, C;

int lC[MAXN], rC[MAXN];
ll tr[MAXN];
// let tr[0] = 0 to represent all blank ranges
int nN = 2;

inline ll gcd(ll X, ll Y) {
    ll tmp;
    while (X != Y && Y != 0) {
        tmp = X;
        X = Y;
        Y = tmp % Y;
    }
    return X;
}

void update1(int i, int l, int r, int x, ll v) {
//    ps("update1", i, l, r, x, v);
    if (l == r) {
        tr[i] = v;
        return;
    }
    int mid = (l + r) / 2;
    if (x <= mid) {
        if (lC[i] == 0) lC[i] = nN++;
        update1(lC[i], l, mid, x, v);
    } else {
        if (rC[i] == 0) rC[i] = nN++;
        update1(rC[i], mid + 1, r, x, v);
    }
    tr[i] = gcd(tr[lC[i]], tr[rC[i]]);
}

ll query1(int i, int l, int r, int s, int e) {
    if (i == 0) return 0; // range all 0's
    if (e < l || r < s) {
        return 0;
    }

    if (s <= l && r <= e) {
        return tr[i];
    }

    int mid = (l + r) / 2;
    return gcd(query1(lC[i], l, mid, s, e), query1(rC[i], mid + 1, r, s, e));
}

ll update2(int i, int l, int r, int x, int y, ll v) {
    if (tr[i] == 0) tr[i] = nN++;
    int cT = tr[i];
//    ps();

    if (l == r) {
        update1(cT, 0, 1e9, y, v);
        return v;
    }

    int mid = (l + r) / 2;

    ll lRes = 0, rRes = 0;
    if (x <= mid) {
        if (lC[i] == 0) lC[i] = nN++;
        lRes = update2(lC[i], l, mid, x, y, v);
        rRes = query1(tr[rC[i]], 0, 1e9, y, y);
    } else {
        if (rC[i] == 0) rC[i] = nN++;
        lRes = query1(tr[lC[i]], 0, 1e9, y, y);
        rRes = update2(rC[i], mid + 1, r, x, y, v);
    }

    ll nVal = gcd(lRes, rRes);
//    ps("update2", i, l, r, x, y, v);
//    ps(nVal);
    update1(cT, 0, 1e9, y, nVal);
    return nVal;
}


ll query2(int i, int l, int r, int s, int e, int s2, int e2) {
    if (i == 0 || tr[i] == 0) return 0;
    if (e < l || r < s) {
        return 0;
    }

    if (s <= l && r <= e) {
        return query1(tr[i], 0, 1e9, s2, e2);
    }

    int mid = (l + r) / 2;
    return gcd(query2(lC[i], l, mid, s, e, s2, e2), query2(rC[i], mid + 1, r, s, e, s2, e2));
}

void init(int iR, int iC) {
    R = iR, C = iC;
}

void update(int P, int Q, ll K) {
//    ps("updating", P, Q, K);

    update2(1, 0, 1e9, P, Q, K);
//    ps(K);
//    if (K == 12) {
//        ps("request");
//        ps(query2(1, 0, 1e9, 0, 1, 0, 2));
//        ps(query2(1, 0, 1e9, 0, 1, 0, 1));
//        ps(query2(1, 0, 1e9, 0, 1, 1, 2));
//    }
//    DEBUG = true;
}

ll calculate(int P, int Q, int U, int V) {
    ll ans = query2(1, 0, 1e9, P, U, Q, V);
    return ans;
}

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 3 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 4 ms 504 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 3 ms 396 KB Output is correct
11 Correct 3 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 1214 ms 32016 KB Output is correct
5 Correct 904 ms 31676 KB Output is correct
6 Correct 1529 ms 29340 KB Output is correct
7 Correct 1534 ms 29084 KB Output is correct
8 Correct 961 ms 19776 KB Output is correct
9 Correct 1471 ms 29180 KB Output is correct
10 Correct 1325 ms 28780 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 4 ms 504 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 4 ms 520 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 1812 ms 15796 KB Output is correct
13 Correct 2965 ms 9100 KB Output is correct
14 Correct 842 ms 5672 KB Output is correct
15 Correct 3399 ms 12020 KB Output is correct
16 Correct 827 ms 16652 KB Output is correct
17 Correct 1844 ms 14168 KB Output is correct
18 Correct 2946 ms 17912 KB Output is correct
19 Correct 2598 ms 18072 KB Output is correct
20 Correct 2376 ms 17592 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 4 ms 504 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 1182 ms 31920 KB Output is correct
13 Correct 890 ms 31608 KB Output is correct
14 Correct 1428 ms 29236 KB Output is correct
15 Correct 1445 ms 29064 KB Output is correct
16 Correct 956 ms 19896 KB Output is correct
17 Correct 1496 ms 29192 KB Output is correct
18 Correct 1255 ms 28720 KB Output is correct
19 Correct 1804 ms 15864 KB Output is correct
20 Correct 2979 ms 9256 KB Output is correct
21 Correct 847 ms 5948 KB Output is correct
22 Correct 3397 ms 11888 KB Output is correct
23 Correct 799 ms 16484 KB Output is correct
24 Correct 1939 ms 14040 KB Output is correct
25 Correct 2999 ms 18004 KB Output is correct
26 Correct 2582 ms 18132 KB Output is correct
27 Correct 2299 ms 17512 KB Output is correct
28 Correct 1010 ms 131064 KB Output is correct
29 Correct 2604 ms 146208 KB Output is correct
30 Correct 8911 ms 107480 KB Output is correct
31 Correct 8562 ms 83740 KB Output is correct
32 Correct 865 ms 5880 KB Output is correct
33 Correct 1155 ms 7288 KB Output is correct
34 Correct 1553 ms 143560 KB Output is correct
35 Correct 2093 ms 75628 KB Output is correct
36 Correct 3841 ms 143712 KB Output is correct
37 Correct 3470 ms 143864 KB Output is correct
38 Correct 2930 ms 142972 KB Output is correct
39 Correct 2486 ms 111556 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 2 ms 296 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 4 ms 508 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 1202 ms 31988 KB Output is correct
13 Correct 901 ms 31656 KB Output is correct
14 Correct 1453 ms 29356 KB Output is correct
15 Correct 1450 ms 28920 KB Output is correct
16 Correct 962 ms 19820 KB Output is correct
17 Correct 1492 ms 29120 KB Output is correct
18 Correct 1308 ms 28880 KB Output is correct
19 Correct 1814 ms 15936 KB Output is correct
20 Correct 2972 ms 9152 KB Output is correct
21 Correct 856 ms 5980 KB Output is correct
22 Correct 3407 ms 11764 KB Output is correct
23 Correct 801 ms 16688 KB Output is correct
24 Correct 1855 ms 13980 KB Output is correct
25 Correct 2923 ms 17632 KB Output is correct
26 Correct 2735 ms 17820 KB Output is correct
27 Correct 2292 ms 17272 KB Output is correct
28 Correct 1054 ms 130068 KB Output is correct
29 Correct 2568 ms 145272 KB Output is correct
30 Correct 8934 ms 106896 KB Output is correct
31 Correct 8485 ms 82856 KB Output is correct
32 Correct 862 ms 5212 KB Output is correct
33 Correct 1111 ms 6776 KB Output is correct
34 Correct 1566 ms 143040 KB Output is correct
35 Correct 1981 ms 74616 KB Output is correct
36 Correct 3725 ms 142536 KB Output is correct
37 Correct 3169 ms 142284 KB Output is correct
38 Correct 3335 ms 141428 KB Output is correct
39 Runtime error 1499 ms 256000 KB Execution killed with signal 9 (could be triggered by violating memory limits)
40 Halted 0 ms 0 KB -