Submission #349833

# Submission time Handle Problem Language Result Execution time Memory
349833 2021-01-18T13:30:21 Z amunduzbaev Game (IOI13_game) C++14
0 / 100
1 ms 364 KB
#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;}

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

int sx, sy;
vector<vll> tree;

void update_r(int x, int y, int val, int lx, int rx, int ly, int ry, int xx, int yy){
	if(ly == ry){
		if(lx == rx) tree[xx][yy] = val;
		else tree[xx][yy] = gcd2(tree[xx*2][yy], tree[xx*2+1][yy]); 
		return; 
	}else{
		int 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] = gcd2(tree[xx][yy*2], tree[xx][yy*2+1]);
	}
}

void upd(int x, int y, int val, int lx, int rx, int xx){
	if(lx != rx){
		int m = (lx + rx)>>1;
		if(x <= m) upd(x, y, val, lx, m, xx*2);
		else upd(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, long long K) {
    upd(++P, ++Q, K, 1, sx, 1);
}

ll qqy(int ly, int ry, int xx, int qly, int qry, int yy){
	if(ly > qry || ry < qly) return (ll)-1;
	if(ly >= qly && ry <= qry) return (ll)tree[xx][yy];
	
	int m = (ly + ry)>>1;
	int res1 = qqy(ly, m, xx, qly, qry, yy*2);
	int res2 = qqy(m+1, ry, xx, qly, qry, yy*2+1);
	
	if(res1 == -1 && res2 == -1) return (ll)-1;
	else if(res2 == -1) return res1;
	else if(res1 == -1) return res2;
	else return gcd2(res1, res2);
}

ll qq(int lx, int rx, int qlx, int qrx, int qly, int qry, int xx){
	//cout<<lx<<" "<<rx<<" "<<qlx<<" "<<qrx<<" "<<qly<<" "<<qry<<"\n";
	if(lx > qrx || rx < qlx) return (ll)-1;
	if(lx >= qlx && rx <= qrx) return qqy(1, sy, xx, qly, qry, 1);
	
	int m = (lx + rx)>>1;
	int res1 = qq(lx, m, qlx, qrx, qly, qry, xx*2);
	int res2 = qq(m+1, rx, qlx, qrx, qly, qry, xx*2+1);
	
	if(res1 == -1 && res2 == -1) return (ll)-1;
	else if(res2 == -1) return res1;
	else if(res1 == -1) return res2;
	else return gcd2(res1, res2);
}

void init(int R, int C) {
	sx = 1, sy = 1;
	
	while(sx < R) sx *= 2;
	while(sy < C) sy *= 2;
	
	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 time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -