제출 #1124351

#제출 시각아이디문제언어결과실행 시간메모리
1124351Joshua_Andersson게임 (IOI13_game)C++20
0 / 100
2 ms324 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; //#define int ll //const int inf = int(1e18); typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> p2; #define rep(i, high) for (int i = 0; i < (high); i++) #define repp(i, low, high) for (int i = (low); i < (high); i++) #define repe(i, container) for (auto& i : container) #define sz(container) ((int)container.size()) #define all(x) begin(x),end(x) inline void fast() { cin.tie(0)->sync_with_stdio(0); } #if _LOCAL #define assert(x) if (!(x)) __debugbreak() #else #include "game.h" #endif long long gcd2(long long X, long long Y) { if (X == -1) return Y; if (Y == -1) return X; long long tmp; while (X != Y && Y != 0) { tmp = X; X = Y; Y = tmp % Y; } return X; } struct tnode { int cnt, prio, c; ll v, acc; tnode *l=0, *r=0; tnode(ll v, int c) : v(v), acc(v), cnt(1), prio(rand()), c(c) {} }; typedef tnode* pnode; int get_cnt(pnode x) { return x ? x->cnt : 0; } int get_acc(pnode x) { return x ? x->cnt : 0; } void pull(pnode x) { if (!x) return; x->cnt = 1 + get_cnt(x->l) + get_cnt(x->r); x->acc = x->v; if (x->l) x->acc = gcd2(x->acc, x->l->acc); if (x->r) x->acc = gcd2(x->acc, x->r->acc); } // first i nodes go to left void split(pnode x, pnode& l, pnode& r, int i, int add = 0) { if (!x) return void(l = r = 0); int real_i = get_cnt(x->l) + add; if (i <= real_i) split(x->l, l, x->l, i, add), r = x; else split(x->r, x->r, r, i, add + get_cnt(x->l) + 1), l = x; pull(x); } void merge(pnode& x, pnode l, pnode r) { if (!l || !r) x = l ? l : r; else if (l->prio < r->prio) merge(r->l, l, r->l), x = r; else merge(l->r, l->r, r), x = l; pull(x); } // count number of nodes with c < key int order_of_key(pnode x, int key) { if (!x) return 0; if (x->c == key) return get_cnt(x->l); else if (x->c < key) return 1 + get_cnt(x->l) + order_of_key(x->r, key); else return order_of_key(x->l, key); } struct snode { int l, r; snode* lc=0, * rc=0; pnode strip=0; snode(int l, int r) : l(l), r(r) {} void insert(int column, ll k) { int ind = order_of_key(strip, column); pnode l, mid, r; split(strip, l, r, ind); if (order_of_key(r, column + 1)) { split(r, mid, r, 1); mid->v = mid->acc = k; } else mid = new tnode(k, column); merge(l, l, mid); merge(strip, l, r); } void update(int row, int column, ll k) { insert(column, k); if (l==r) { return; } int mid = (l + r) / 2; if (row <= mid) { if (!lc) lc = new snode(l, mid); lc->update(row, column, k); } else { if (!rc) rc = new snode(mid + 1, r); rc->update(row, column, k); } } ll query(int rowl, int rowr, int coll, int colr) { if (l > rowr || r < rowl) { return -1; } if (l >= rowl && r <= rowr) { int lind = order_of_key(strip, coll); int rind = order_of_key(strip, colr + 1); pnode l, mid, r; split(strip, mid, r, rind); split(mid, l, mid, lind); ll ret = -1; if (mid) { if (ret == -1) ret = mid->acc; else ret = gcd2(ret, mid->acc); } merge(l, l, mid); merge(strip, l, r); return ret; } ll ret = -1; if (lc) ret = gcd2(ret, lc->query(rowl, rowr, coll, colr)); if (rc) ret = gcd2(ret, rc->query(rowl, rowr, coll, colr)); return ret; } }; snode* root; void init(int R, int C) { root = new snode(0, R - 1); } void update(int P, int Q, long long K) { root->update(P, Q, K); } long long calculate(int P, int Q, int U, int V) { ll ret = root->query(P, U, Q, V); if (ret == -1) ret = 0; return ret; } // //void solve() //{ // //} // //signed main() //{ // fast(); // // int r, c, q; // cin >> r >> c >> q; // init(r, c); // while (q--) // { // int t; // cin >> t; // if (t==1) // { // int a, b, c; // cin >> a >> b >> c; // update(a, b, c); // } // else // { // int a, b, c, d; // cin >> a >> b >> c >> d; // cout << calculate(a, b, c, d) << "\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...