Submission #349844

#TimeUsernameProblemLanguageResultExecution timeMemory
349844amunduzbaevGame (IOI13_game)C++14
63 / 100
1819 ms136568 KiB
#include "game.h" #ifndef EVAL #include "grader.cpp" #endif #include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back #define mp make_pair #define ub upper_bound #define lb lower_bound #define ll long long #define ld long double #define pii pair<int, int> #define pll pair<ll, ll> #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(),x.rend() #define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define vll vector<ll> #define vii vector<int> #define vpii vector<pii> #define vpll vector<pll> #define cnt(a)__builtin_popcount(a) template<class T> bool umin(T& a, const T& b) {return a > b? a = b, true:false;} template<class T> bool umax(T& a, const T& b) {return a < b? a = b, true:false;} ll sx, sy; vector<vector<ll>> tree; ll gcd2(ll X, ll Y) { ll tmp; while (X != Y && Y != 0){ tmp = X, X = Y, Y = tmp % Y; }return X; } void update_r(ll x, ll y, ll val, ll lx, ll rx, ll ly, ll ry, ll xx, ll yy){ if(ly == ry){ if(lx == rx) tree[xx][yy] = (ll)val; else tree[xx][yy] = (ll)gcd2(tree[xx*2][yy], tree[xx*2+1][yy]); }else{ ll m = (ly + ry)>>1; if(y <= m) update_r(x, y, val, lx, rx, ly, m, xx, yy*2); else update_r(x, y, val, lx, rx, m+1, ry, xx, yy*2+1); tree[xx][yy] = (ll)gcd2(tree[xx][yy*2], tree[xx][yy*2+1]); } } void update_c(ll x, ll y, ll val, ll lx, ll rx, ll xx){ if(lx != rx){ ll m = (lx + rx)>>1; if(x <= m) update_c(x, y, val, lx, m, xx*2); else update_c(x, y, val, m+1, rx, xx*2+1); } update_r(x, y, val, lx, rx, 1, sy, xx, 1); } void update(int P, int Q, ll K) { update_c(++P, ++Q, K, 1, sx, 1); } ll qqy(ll ly, ll ry, ll xx, ll qly, ll qry, ll yy){ if(ly > qry || ry < qly) return 0ll; if(ly >= qly && ry <= qry) return (ll)tree[xx][yy]; int m = (ly + ry)>>1; ll res1 = (ll)qqy(ly, m, xx, qly, qry, yy*2); ll res2 = (ll)qqy(m+1, ry, xx, qly, qry, yy*2+1); return (ll)gcd2(res1, res2); } ll qq(ll lx, ll rx, ll qlx, ll qrx, ll qly, ll qry, ll xx){ if(lx > qrx || rx < qlx) return 0ll; if(lx >= qlx && rx <= qrx) return (ll)qqy(1, sy, xx, qly, qry, 1); int m = (lx + rx)>>1; ll res1 = (ll)qq(lx, m, qlx, qrx, qly, qry, xx*2); ll res2 = (ll)qq(m+1, rx, qlx, qrx, qly, qry, xx*2+1); return (ll)gcd2(res1, res2); } void init(int R, int C) { sx = 1, sy = 1; while(sx < R) sx <<= 1; while(sy < C) sy <<= 1; tree.assign(sx*2, vll(sy*2, 0ll)); } ll calculate(int x, int y, int xx, int yy) { return qq(1, sx, min(x, xx)+1, max(x, xx)+1, min(y, yy)+1, max(y, yy)+1, 1); }
#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...