Submission #1261233

#TimeUsernameProblemLanguageResultExecution timeMemory
1261233repmannGame (IOI13_game)C++20
80 / 100
3188 ms269572 KiB
#include <bits/stdc++.h> #include "game.h" #define ll long long using namespace std; int cntR, cntC; struct ColNode { ll gcd; int L, R; }COL[19800000]; struct RowNode { ll gcd; int L, R; int col; }ROW[660000]; void init(int R, int C) { cntR = 1; return; } void Merge(ColNode *node) { node->gcd = __gcd(COL[node->L].gcd, COL[node->R].gcd); return; } void ColUpdate(int j, ll x, ColNode *node, int LC = 1, int RC = 1 << 30) { if(LC == RC) { node->gcd = x; return; } int S = (LC + RC) >> 1; if(j <= S) { if(!node->L) node->L = ++cntC; ColUpdate(j, x, &COL[node->L], LC, S); } else { if(!node->R) node->R = ++cntC; ColUpdate(j, x, &COL[node->R], S + 1, RC); } Merge(node); return; } ll ColPoint(int j, ColNode *node, int LC = 1, int RC = 1 << 30) { if(node == COL) return 0; if(LC == RC) return node->gcd; int S = (LC + RC) >> 1; if(j <= S) { if(!node->L) return 0; return ColPoint(j, &COL[node->L], LC, S); } else { if(!node->R) return 0; return ColPoint(j, &COL[node->R], S + 1, RC); } return 0; } void Update(int i, int j, ll x, RowNode *node, int LC = 1, int RC = 1 << 30) { if(LC == RC) { if(!node->col) node->col = ++cntC; ColUpdate(j, x, &COL[node->col]); return; } int S = (LC + RC) >> 1; if(i <= S) { if(!node->L) node->L = ++cntR; Update(i, j, x, &ROW[node->L], LC, S); } else { if(!node->R) node->R = ++cntR; Update(i, j, x, &ROW[node->R], S + 1, RC); } if(!node->col) node->col = ++cntC; ll l = 0, r = 0; if(node->L) l = ColPoint(j, &COL[ROW[node->L].col]); if(node->R) r = ColPoint(j, &COL[ROW[node->R].col]); ColUpdate(j, __gcd(l, r), &COL[node->col]); return; } void update(int i, int j, ll x) { i++; j++; Update(i, j, x, &ROW[1]); return; } ll ColGet(int j, int l, ColNode *node, int LC = 1, int RC = 1 << 30) { if(node == COL) return 0; if((LC > l) || (j > RC)) return 0; if((j <= LC) && (RC <= l)) return node->gcd; int S = (LC + RC) >> 1; return __gcd(ColGet(j, l, &COL[node->L], LC, S), ColGet(j, l, &COL[node->R], S + 1, RC)); } ll Get(int i, int j, int k, int l, RowNode *node, int LC = 1, int RC = 1 << 30) { if(node == ROW) return 0; if((LC > k) || (i > RC)) return 0; if((i <= LC) && (RC <= k)) { if(!node->col) return 0; return ColGet(j, l, &COL[node->col]); } int S = (LC + RC) >> 1; return __gcd(Get(i, j, k, l, &ROW[node->L], LC, S), Get(i, j, k, l, &ROW[node->R], S + 1, RC)); } ll calculate(int i, int j, int k, int l) { i++; j++; k++; l++; return Get(i, j, k, l, &ROW[1]); } //int main() //{ // int r, c; // cin >> r >> c; // init(r, c); // int t, i, j, l; // ll k; // while(true) // { // cin >> t >> i >> j >> k; // if(t == 1) update(i, j, k); // else // { // cin >> l; // cout << calculate(i, j, k, l) << '\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...