Submission #1112094

# Submission time Handle Problem Language Result Execution time Memory
1112094 2024-11-13T16:23:25 Z steveonalex Game (IOI13_game) C++17
0 / 100
2 ms 504 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 = 1e9 + 69;
struct Trie{
    struct Node{
        int child[2];
        ll g;
        Node(){g = 0; memset(child, -1, sizeof child);}
    };

    int l, r;
    vector<Node> a;

    Trie(){}
    Trie(int l, int r): l(l), r(r){
        a.push_back(Node());
    }

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

    void update(int i, ll k, int l, int r, int id){
        if (l == r){a[id].g = k; return;}
        int mid = (l + r) >> 1;
        if (i <= mid){
            if (a[id].child[0] == -1) add_child(a[id].child[0]);
            update(i, k, l, mid, a[id].child[0]);
        }
        else{
            if (a[id].child[1] == -1) add_child(a[id].child[1]);
            update(i, k, mid + 1, r, a[id].child[1]);
        }
        a[id].g = 0;
        for(int i = 0; i <= 1; ++i)
        if (a[id].child[i] != -1) a[id].g = gcd(a[id].g, a[a[id].child[i]].g);
    }

    void update(int i, ll k){
        update(i, k, l, r, 0);
    }

    ll get(int u, int v, int l, int r, int id){
        if (u <= l && r <= v) return a[id].g;
        int mid = (l + r) >> 1;
        ll ans = 0;
        if (u <= mid && a[id].child[0] != -1) ans = gcd(ans, get(u, v, l, mid, a[id].child[0]));
        if (v > mid && a[id].child[1] != -1) ans = gcd(ans, get(u, v, mid + 1, r, a[id].child[1]));
        return ans;
    }

    ll get(int u, int v){return get(u, v, l, r, 0);}
};

struct Trie2D{
    struct Node{
        int child[2];
        Trie g;
        Node(){g = Trie(0, INF); memset(child, -1, sizeof child);}
    };

    int l, r;
    vector<Node> a;

    Trie2D(){}
    Trie2D(int l, int r): l(l), r(r){
        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 l, int r, int id){
        a[id].g.update(j, k);
        if (l == r) return;
        int mid = (l + r) >> 1;
        if (i <= mid){
            if (a[id].child[0] == -1) add_child(a[id].child[0]);
            update(i, j, k, l, mid, a[id].child[0]);
        }
        else{
            if (a[id].child[1] == -1) add_child(a[id].child[1]);
            update(i, j, k, mid + 1, r, a[id].child[1]);
        }
    }

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

    ll get(int u, int v, int x, int y, int l, int r, int id){
        if (u <= l && r <= v) return a[id].g.get(x, y);
        int mid = (l + r) >> 1;
        ll ans = 0;
        if (u <= mid && a[id].child[0] != -1) ans = gcd(ans, get(u, v, x, y, l, mid, a[id].child[0]));
        if (v > mid && a[id].child[1] != -1) ans = gcd(ans, get(u, v, x, y, mid + 1, r, a[id].child[1]));
        return ans;
    }

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

Trie2D 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, U, Q, V);
}


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

//     clock_t start = clock();

//     // solve();

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

//     return 0;
// }
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 336 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 336 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 504 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 336 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 336 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -