Submission #98934

# Submission time Handle Problem Language Result Execution time Memory
98934 2019-02-27T15:13:04 Z jhnah917 Game (IOI13_game) C++14
0 / 100
234 ms 257024 KB
#ifndef __GAME_H__
#define __GAME_H__
 
#ifdef __cplusplus
extern "C" {
#endif
 
#include <math.h>
 
void init(int R, int C);
void update(int P, int Q, long long K);
long long calculate(int P, int Q, int U, int V);
int r, c;

typedef long long ll;

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

struct Seg1d{
	ll arr[4*2020];
	
	Seg1d(){
		for(int i=0; i<8080; i++) arr[i] = 0;
	}	

	void update(int node, int s, int e, int y, ll val){
		if(e < y || y < s) return;
		if(s == e){
			arr[node] = val; return;
		}
		int m = s + e >> 1;
		update(node*2, s, m, y, val);
		update(node*2+1, m+1, e, y, val);
		arr[node] = f(arr[node*2], arr[node*2+1]);
	}
	ll query(int node, int s, int e, int l, int r){
		if(r < s || e < l) return 0;
		if(l <= s && e <= r) return arr[node];
		int m = s + e >> 1;
		return f(query(node*2, s, m, l, r), query(node*2+1, m+1, e, l, r));
	}
};

struct Seg2d{
	Seg1d arr[4*2020];
	
	void update(int node, int s, int e, int x, int y, ll val){
		if(e < x || x < s) return;
		if(s == e){
			arr[node].update(1, 0, c-1, y, val); return;
		}
		int m = s + e >> 1;
		update(node*2, s, m, x, y, val);
		update(node*2+1, m+1, e, x, y, val);
		arr[node].update(1, 0, c-1, y, val);
	}
	
	ll query(int node, int s, int e, int x1, int x2, int y1, int y2){
		if(x2 < s || e < x1) return 0;
		if(x1 <= s && e <= x2) return arr[node].query(1, 0, c-1, y1, y2);
		int m = s + e >> 1;
		ll t1 = query(node*2, s, m, x1, x2, y1, y2);
		ll t2 = query(node*2+1, m+1, e, x1, x2, y1, y2);
		return f(t1, t2);
	}
} tree;
 
void init(int R, int C) {
	r = R, c = C;
}
 
void update(int x, int y, long long val) {
    tree.update(1, 0, r-1, x, y, val);
}
 
long long calculate(int x1, int y1, int x2, int y2) {
    return tree.query(1, 0, r-1, x1, x2, y1, y2);
}
 
#ifdef __cplusplus
}
#endif
 
#endif /* __GAME_H__ */

Compilation message

grader.c: In function 'int main()':
grader.c:18:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
  int res;
      ^~~
game.cpp: In member function 'void Seg1d::update(int, int, int, int, ll)':
game.cpp:39:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = s + e >> 1;
           ~~^~~
game.cpp: In member function 'll Seg1d::query(int, int, int, int, int)':
game.cpp:47:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = s + e >> 1;
           ~~^~~
game.cpp: In member function 'void Seg2d::update(int, int, int, int, int, ll)':
game.cpp:60:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = s + e >> 1;
           ~~^~~
game.cpp: In member function 'll Seg2d::query(int, int, int, int, int, int, int)':
game.cpp:69:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = s + e >> 1;
           ~~^~~
# Verdict Execution time Memory Grader output
1 Runtime error 197 ms 257024 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 221 ms 257024 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 234 ms 257024 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 225 ms 257024 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 230 ms 257024 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -