Submission #1112334

#TimeUsernameProblemLanguageResultExecution timeMemory
1112334steveonalexGame (IOI13_game)C++17
80 / 100
2562 ms256000 KiB
#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){ if (l == r) {a[id].g.update(j, k); 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]); } ll ans = 0; for(int i = 0; i <= 1; ++i) if (a[id].child[i] != -1) ans = gcd(ans, a[a[id].child[i]].g.get(j, j)); a[id].g.update(j, ans); } 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) { tri = Trie2D(0, INF); } 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(); // init(2, 3); // update(0, 0, 20); // update(0, 2, 15); // update(1, 1, 12); // cout << calculate(0, 0, 0, 2) << "\n"; // cerr << "Time elapsed: " << clock() - start << " ms!\n"; // return 0; // }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...