답안 #373735

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373735 2021-03-05T14:37:39 Z cheissmart 게임 (IOI13_game) C++14
63 / 100
2032 ms 256004 KB
#include "game.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define V vector
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "LINE(" << __LINE__ << ") -> " << #x << " is " << (x) << endl
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
 
const int INF = 1e9 + 7;

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

int R, C;

struct seg_y {
    struct node {
        node *l, *r;
        ll g; // gcd
        node(int _g = 0) {
            l = r = nullptr;
            g = _g;
        }
    };
    node* root;
    seg_y() {
        root = nullptr;
    }
    ll g(node* t) {
        return t ? t -> g : 0LL;
    }
    void pull(node* t) {   
        t -> g = gcd2(g(t -> l), g(t -> r));
    }
    void upd(node* &t, int y, ll val, int tl = 0, int tr = C) {
        if(!t) t = new node();
        if(tr - tl == 1) {
            t -> g = val;
            return;
        }
        int tm = (tl + tr) / 2;
        if(y < tm) upd(t -> l, y, val, tl, tm);
        else upd(t -> r, y, val, tm, tr);
        pull(t);
    }
    ll qry(node* t, int l, int r, int tl = 0, int tr = C) {
        if(!t) return 0;
        if(l <= tl && tr <= r) return t -> g;
        int tm = (tl + tr) / 2;
        ll g = 0;
        if(l < tm) g = gcd2(g, qry(t -> l, l, r, tl, tm));
        if(r > tm) g = gcd2(g, qry(t -> r, l, r, tm, tr));
        return g;
    }
    void upd(int y, ll val) {
        upd(root, y, val);
    }
    ll qry(int l, int r) {
        return qry(root, l, r);
    }
    ll qry(int y) {
        return qry(y, y + 1);
    }
};

struct seg_x {
    struct node {
        node *l, *r;
        seg_y seg;
        node() {
            l = r = nullptr;
        }
    };
    node* root;
    void pull(node* t, int y) {
        ll g = 0;
        if(t -> l) g = gcd2(g, t -> l -> seg.qry(y));
        if(t -> r) g = gcd2(g, t -> r -> seg.qry(y));
        t -> seg.upd(y, g);
    }
    void upd(node* &t, int x, int y, ll val, int tl = 0, int tr = R) {
        if(!t) t = new node();
        if(tr - tl == 1) {
            t -> seg.upd(y, val);
            return;
        }
        int tm = (tl + tr) / 2;
        if(x < tm) upd(t -> l, x, y, val, tl, tm);
        else upd(t -> r, x, y, val, tm, tr);
        pull(t, y);
    }
    void upd(int x, int y, ll val) {
        upd(root, x, y, val);
    }
    ll qry(node* t, int xl, int xr, int yl, int yr, int tl = 0, int tr = R) {
        if(!t) return 0;
        if(xl <= tl && tr <= xr) return t -> seg.qry(yl, yr);
        int tm = (tl + tr) / 2;
        ll g = 0;
        if(xl < tm) g = gcd2(g, qry(t -> l, xl, xr, yl, yr, tl, tm));
        if(xr > tm) g = gcd2(g, qry(t -> r, xl, xr, yl, yr, tm, tr));
        return g;
    }
    ll qry(int xl, int xr, int yl, int yr) {
        return qry(root, xl, xr, yl, yr);
    }
} seg;

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

void update(int P, int Q, long long K) {
    seg.upd(P, Q, K);
}

long long calculate(int P, int Q, int U, int V) {
    return seg.qry(P, U + 1, Q, V + 1);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 548 ms 17260 KB Output is correct
5 Correct 415 ms 17004 KB Output is correct
6 Correct 508 ms 14444 KB Output is correct
7 Correct 554 ms 14276 KB Output is correct
8 Correct 354 ms 10988 KB Output is correct
9 Correct 553 ms 14572 KB Output is correct
10 Correct 512 ms 14060 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 849 ms 19948 KB Output is correct
13 Correct 1376 ms 10080 KB Output is correct
14 Correct 308 ms 5740 KB Output is correct
15 Correct 1647 ms 13548 KB Output is correct
16 Correct 244 ms 22508 KB Output is correct
17 Correct 848 ms 16492 KB Output is correct
18 Correct 1546 ms 24132 KB Output is correct
19 Correct 1290 ms 24428 KB Output is correct
20 Correct 1222 ms 23496 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 554 ms 17132 KB Output is correct
13 Correct 417 ms 17004 KB Output is correct
14 Correct 514 ms 14572 KB Output is correct
15 Correct 578 ms 14316 KB Output is correct
16 Correct 354 ms 11116 KB Output is correct
17 Correct 542 ms 14444 KB Output is correct
18 Correct 526 ms 14060 KB Output is correct
19 Correct 875 ms 20272 KB Output is correct
20 Correct 1377 ms 10200 KB Output is correct
21 Correct 293 ms 5740 KB Output is correct
22 Correct 1646 ms 13432 KB Output is correct
23 Correct 243 ms 22676 KB Output is correct
24 Correct 849 ms 16420 KB Output is correct
25 Correct 1537 ms 24368 KB Output is correct
26 Correct 1275 ms 24428 KB Output is correct
27 Correct 1187 ms 23660 KB Output is correct
28 Correct 1124 ms 256000 KB Output is correct
29 Runtime error 2032 ms 256004 KB Execution killed with signal 9
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 549 ms 17388 KB Output is correct
13 Correct 415 ms 16876 KB Output is correct
14 Correct 526 ms 14444 KB Output is correct
15 Correct 587 ms 14316 KB Output is correct
16 Correct 374 ms 11116 KB Output is correct
17 Correct 575 ms 14572 KB Output is correct
18 Correct 544 ms 13932 KB Output is correct
19 Correct 859 ms 20076 KB Output is correct
20 Correct 1385 ms 10364 KB Output is correct
21 Correct 309 ms 5740 KB Output is correct
22 Correct 1656 ms 13548 KB Output is correct
23 Correct 245 ms 22508 KB Output is correct
24 Correct 889 ms 16548 KB Output is correct
25 Correct 1573 ms 24072 KB Output is correct
26 Correct 1324 ms 24372 KB Output is correct
27 Correct 1248 ms 23916 KB Output is correct
28 Correct 1094 ms 256000 KB Output is correct
29 Runtime error 2009 ms 256004 KB Execution killed with signal 9
30 Halted 0 ms 0 KB -