답안 #1112160

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1112160 2024-11-13T17:32:19 Z steveonalex 게임 (IOI13_game) C++17
0 / 100
1 ms 444 KB
#include <bits/stdc++.h>
#include "game.h"

using namespace std;

typedef long long ll;
typedef unsigned int ul;
typedef unsigned long long ull;

#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()

ll gcd(ll a, ll b){return __gcd(a, b);}
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}

template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }

template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }

template <class T>
    void printArr(T the_array_itself, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: the_array_itself) out << item << separator;
        out << finish;
    }

template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

const int INF = MASK(5) - 1;
const int BIT = 5;

struct QuadTree{
    struct Node{
        int child[4];
        ll g;

        Node(){g = 0; memset(child, -1, sizeof child);}
    };

    vector<Node> a;

    QuadTree(){
        a.push_back(Node());
    }

    void add_child(int &x){
        x = a.size();
        a.push_back(Node());
    }

    void update(int i, int j, ll k, int bit, int id){
        if (bit == 0){
            a[id].g = k;
            return;
        }
        int digit = GETBIT(i, bit-1) + GETBIT(j, bit-1) * 2;
        if (a[id].child[digit] == -1) add_child(a[id].child[digit]);
        update(i, j, k, bit - 1, a[id].child[digit]);

        a[id].g = 0;
        for(int it = 0; it < 4; ++it) 
            if (a[id].child[it] != -1) a[id].g = gcd(a[id].g, a[a[id].child[it]].g);
    }

    void update(int i, int j, ll k){
        update(i, j, k, BIT, 0);
    }

    ll get(int u, int v, int x, int y, int bit, int id){
        // cout << "Get: " << bit << " " << u << " " << v << " " << x << " " << y << "\n";
        int cu = MASK(bit) - 1;
        if (u == 0 && v == 0 && x == cu && y == cu) return a[id].g;
        ll ans = 0;
        for(int it = 0; it < 4; ++it) if (a[id].child[it] != -1){
            int _u = u, _v = v, _x = x, _y = y;
            int cu = MASK(bit-1);
            if (GETBIT(it, 0)) {
                _u -= cu;
                _x -= cu;
            }
            if (GETBIT(it, 1)){
                _v -= cu;
                _y -= cu;
            }

            maximize(_u, 0); maximize(_v, 0);
            minimize(_x, cu-1); minimize(_y, cu-1);
            if (_u > _x || _v > _y) continue;
            // cout << "Go digit: " << it << "\n";
            // cout << _y << "\n";
            ans = gcd(ans, get(_u, _v, _x, _y, bit - 1, a[id].child[it]));
        }

        return ans;
    }

    ll get(int u, int v, int x, int y){
        return get(u, v, x, y, BIT, 0);
    }
};

QuadTree tri;

void init(int R, int C) {
}

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

long long calculate(int P, int Q, int U, int V) {
    if (P > U) swap(P, U);
    if (Q > V) swap(Q, V);
    return tri.get(P, Q, U, V);
}


// int main(void){
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//     clock_t start = clock();

//     init(10, 10);
//     int q; cin >> q;
//     while(q--){
//         int type; cin >> type;
//         if (type == 1){
//             int p, q; ll k; cin >> p >> q >> k;
//             update(p, q, k);
//         }
//         else{
//             int p, q, u, v; cin >> p >> q >> u >> v;
//             cout << calculate(p, q, u, v) << "\n";
//         }
//     }

//     cerr << "Time elapsed: " << clock() - start << " ms!\n";

//     return 0;
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 1 ms 444 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -