Submission #1025606

# Submission time Handle Problem Language Result Execution time Memory
1025606 2024-07-17T08:06:16 Z dozer Game (IOI13_game) C++14
0 / 100
1 ms 604 KB
#include <bits/stdc++.h>
#include "game.h"
using namespace std;
#define sp " "
#define endl "\n"
#define pb push_back
#define pii pair<int,int>
#define st first
#define nd second
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define LL node * 2
#define RR node * 2 + 1
#define mid (l + r) / 2
#define ll long long
#define MAXN 200005


long long gcd2(long long X, long long Y) {
    long long tmp;
    while (X != Y && Y != 0) {
        tmp = X;
        X = Y;
        Y = tmp % Y;
    }
    return X;
}


struct Node{
	ll valy;
	Node *XL, *XR, *YR, *YL;
	Node(){
		XL = XR = YL = YR = NULL;
		valy = 0;
	}

	Node (ll v2){
		XL = XR = YL = YR = NULL;
		valy = v2;
	}

	Node (Node *other){
		XL = other->XL;
		XR = other->XR;
		YL = other->YL;
		YR = other->YR;
		valy = other->valy;
	}


	void pull_y(){
		ll lft = 0, rgt = 0;
		if (YL != NULL) lft = YL->valy;
		if (YR != NULL) rgt = YR->valy;
		valy = gcd2(lft, rgt);
	}
};


typedef Node* pnode;

struct SegTree{
	pnode root;

	int R, C;

	SegTree(){
		root = new Node();
	}

	SegTree(int r, int c){
		root = new Node();
		R = r, C = c;
	}

	void update_y(pnode node, int l, int r, int sl, ll val){
		if (l > sl || r < sl) return;
		if (l == r){
			node->valy = val;
			return;
		}

		if (sl <= mid){
			if (node->YL == NULL){
				node->YL = new Node();
			}
			update_y(node->YL, l, mid, sl, val);
		}

		else{
			if (node->YR == NULL){
				node->YR = new Node();
			}

			update_y(node->YR, mid + 1, r, sl, val);
		}

		node->pull_y();
	}

	void update_x(pnode node, int l, int r, int x, int y, ll val){
		if (l > x || r < x) return;
		update_y(node, 1, C, y, val);
		if (l == r) return;

		if (x <= mid){
			if (node->XL == NULL){
				node->XL = new Node();
			}
			update_x(node->XL, l, mid, x, y, val);
		}

		else{
			if (node->XR == NULL){
				node->XR = new Node();
			}
			update_x(node->XR, mid + 1, r, x, y, val);
		}
	}
	void update(int x, int y, ll val){
		update_x(root, 1, R, x, y, val);
	}


	ll query_y(pnode node, int l, int r, int sl, int sr){
		if (l > sr || r < sl) return 0;
		if (l >= sl && r <= sr) return node->valy;
		ll lft = 0, rgt = 0;
		if (node->YL != NULL && sl <= mid) lft = query_y(node->YL, l, mid, sl, sr);
		if (node->YR != NULL && sr > mid) rgt = query_y(node->YR, mid + 1, r, sl, sr);
		return gcd2(lft, rgt);
	}

	ll query_x(pnode node, int l, int r, int slx, int srx, int sly, int sry){
		if (l > srx || r < slx) return 0;
		if (l >= slx && r <= srx) return query_y(node, 1, C, sly, sry);
		int lft = 0, rgt = 0;
		if (node->XL != NULL && slx <= mid){
			lft = query_x(node->XL, l, mid, slx, srx, sly, sry);
		}

		if (node->XR != NULL && srx > mid){
			rgt = query_x(node->XR, mid + 1, r, slx, srx, sly, sry);
		}

		return gcd2(lft, rgt);
	}

	ll query(int slx, int srx, int sly, int sry){
		return query_x(root, 1, R, slx, srx, sly, sry);
	}
};



SegTree *t;

void init(int R, int C) {
    t = new SegTree(R, C);
}

void update(int P, int Q, long long K) {
    t->update(P + 1, Q + 1, K);
}

long long calculate(int P, int Q, int U, int V) {
    P++, Q++, U++, V++;
    return t->query(P, U, Q, V);
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -