Submission #900871

#TimeUsernameProblemLanguageResultExecution timeMemory
900871trMatherzGame (IOI13_game)C++17
Compilation error
0 ms0 KiB
//#include <iostream> //cin, cout
#include "game.h"
/*
#include <fstream>
std::ifstream cin ("ex.in");
std::ofstream cout ("ex.out");
*/




// includes
#include <cmath> 
#include <set>
#include <map>
#include <queue>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <unordered_set>
#include <stack>
#include <ext/pb_ds/assoc_container.hpp>
#include <random>
#include <chrono>



//usings 
using namespace std;
using namespace __gnu_pbds;


// misc
#define ll long long
#define pb push_back
#define pq priority_queue
#define ub upper_bound
#define lb lower_bound
template<typename T, typename U> bool emin(T &a, const U &b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool emax(T &a, const U &b){ return b > a ? a = b, true : false; }
typedef uint64_t hash_t;

// vectors
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vpii vector<pair<int, int>>
#define vvpii vector<vector<pair<int, int>>>
#define vppipi vector<pair<int, pair<int, int>>>
#define vl vector<ll>
#define vvl vector<vl>
#define vvvl vector<vvl>
#define vpll vector<pair<ll, ll>>
#define vb vector<bool>
#define vvb vector<vb>
#define vs vector<string>
#define sz(x) (int)x.size()
#define rz resize
#define all(x) x.begin(), x.end()


// pairs
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define f first
#define s second

// sets
#define si set<int>
#define sl set<ll>
#define ss set<string>
#define in insert
template <class T> using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// maps
#define mii map<int, int>
#define mll map<ll, ll>

// loops
#define FR(x, z, y) for (int x = z; x < y; x++)
#define FRe(x, z, y) FR(x, z, y + 1)
#define F(x, y) FR(x, 0, y)
#define Fe(x, y) F(x, y + 1)
#define A(x, y) for(auto &x : y)

int Y, X;
struct Xnode{
	Xnode(int x, int y) : l(x), r(y), v(0), lc(NULL), rc(NULL) {}
	ll v; 
	int l, r;
	Xnode *lc, *rc;
};

struct Ynode{
	Ynode() : lc(NULL), rc(NULL), node(NULL) {}
	Xnode *node;
	Ynode *lc, *rc;
} *root;

ll gcd2(ll x, ll y){
	if(y == 0) return x;
	return gcd2(y, x % y);
}




void upd2(Xnode *cur, int x, ll v){
	int l = cur->l, r = cur->r, m = (r + l) / 2;
	if(l == r){
		cur->v = v;
		return;
	}
	Xnode **child = &(x <= m ? cur->lc : cur->rc);
	if(*child == NULL){
		*child = new Xnode(x, x);
		(*child)->v = v;
	} else if((*child)->l <= x && x <= (*child)->r) {
		upd2(*child, x, v);
	} else{
		do {
			if(x <= m) r = m;
			else l = m + 1;
			m = (r + l) / 2;
		} while((x <= m) == ((*child)->r <= m));
		Xnode *ccur = new Node(l, r);
		if((*child)->r <= m) ccur->lc = *child;
		else ccur->rc = *child;
		*child = ccur;
		upd2(*child, x, v);
	}
	cur->v = gcd2(cur->lc ? cur->lc->v : 0, cur->rc ? cur->rc->v : 0);
}

void upd1(Ynode *cur, int l, int r, int y, int x, ll v){
	if(l == r) {upd2(cur->node, x, v); return;}
	int m = (r + l) / 2;
	if(y <= m){
		if(!cur->lc) cur->lc = new Ynode;
		upd1(cur->lc, l, m, y, x, v);
	} else {
		if(!cur->rc) cur->rc = new Ynode;
		upd1(cur->rc, m + 1, r, y, x, v);
	}
	ll z = gcd2(cur->lc ? get2(&cur->lc->node, x, x) : 0, cur->rc ? get2(&cur->rc->node, x, x) : 0);
	upd2(cur->node, x, z);
}

ll get2(Xnode *cur, int rl, int rr){
	if(cur == NULL || cur->r < rl || cur->l > rr) return 0;
	if(rl <= cur->l && cur->r <= rr)  return cur->v;
	return gcd2(get2(cur->lc, rl, rr), get2(cur->rc, rl, rr));
}

ll get1(Ynode *cur, int l, int r, int rl, int rr, int xl, int xr){
	if(cur == NULL || l > rr || r < rl) return 0;
	if(rl <= l && r <= rr) return get2(cur->node, xl, xr);
	int m = (r + l) / 2;
	return gcd(get1(cur->lc, l, m, rl, rr, xl, xr), get1(cur->rc, m + 1, r, rl, rr, xl, xr));
}


void init(int R, int C){
	Y = R, X = C;
	root = new Ynode;
}

void update(int P, int Q, ll K){
	P++; Q++;
	upd1(root, 1, Y, P, Q, K);
}

ll calculate(int P, int Q, int U, int V){
	P++; Q++; U++; V++;
	return get1(root, 1, Y, P, U, Q, V);
}

Compilation message (stderr)

game.cpp: In constructor 'Xnode::Xnode(int, int)':
game.cpp:94:9: warning: 'Xnode::r' will be initialized after [-Wreorder]
   94 |  int l, r;
      |         ^
game.cpp:93:5: warning:   'long long int Xnode::v' [-Wreorder]
   93 |  ll v;
      |     ^
game.cpp:92:2: warning:   when initialized here [-Wreorder]
   92 |  Xnode(int x, int y) : l(x), r(y), v(0), lc(NULL), rc(NULL) {}
      |  ^~~~~
game.cpp: In constructor 'Ynode::Ynode()':
game.cpp:101:14: warning: 'Ynode::rc' will be initialized after [-Wreorder]
  101 |  Ynode *lc, *rc;
      |              ^~
game.cpp:100:9: warning:   'Xnode* Ynode::node' [-Wreorder]
  100 |  Xnode *node;
      |         ^~~~
game.cpp:99:2: warning:   when initialized here [-Wreorder]
   99 |  Ynode() : lc(NULL), rc(NULL), node(NULL) {}
      |  ^~~~~
game.cpp: In function 'void upd2(Xnode*, int, long long int)':
game.cpp:130:21: error: expected type-specifier before 'Node'
  130 |   Xnode *ccur = new Node(l, r);
      |                     ^~~~
game.cpp: In function 'void upd1(Ynode*, int, int, int, int, long long int)':
game.cpp:149:24: error: 'get2' was not declared in this scope; did you mean 'getw'?
  149 |  ll z = gcd2(cur->lc ? get2(&cur->lc->node, x, x) : 0, cur->rc ? get2(&cur->rc->node, x, x) : 0);
      |                        ^~~~
      |                        getw