Submission #24050

# Submission time Handle Problem Language Result Execution time Memory
24050 2017-05-29T23:44:15 Z RezwanArefin01 Game (IOI13_game) C++14
Compilation error
0 ms 0 KB
/*/////////////////////////////
2D Segment Tree 
Needs O(16nm) memory!!! 
Be carefull writing lx, rx, ly, ry! 
//////////////////////////////*/

const int maxn = 2001;
int tree[4*maxn][4*maxn], n, m, arr[maxn][maxn];
void buildY(int ndx, int lx, int rx, int ndy, int ly, int ry) {
	if(ly == ry) {
		if(lx == rx) tree[ndx][ndy] = arr[lx][ly];
		else tree[ndx][ndy] = tree[ndx*2][ndy] + tree[ndx*2+1][ndy];
		return;
	} int mid = ly + ry >> 1;
	buildY(ndx, lx, rx, ndy*2, ly, mid);
	buildY(ndx, lx, rx, ndy*2+1, mid+1, ry);
	tree[ndx][ndy] = tree[ndx][ndy*2] + tree[ndx][ndy*2+1];
}
void buildX(int ndx, int lx, int rx) {
	if(lx != rx) {
		int mid = lx + rx >> 1;
		buildX(ndx*2, lx, mid);
		buildX(ndx*2+1, mid+1, rx);
	} buildY(ndx, lx, rx, 1, 0, m-1);
}
void updateY(int ndx, int lx, int rx, int ndy, int ly, int ry, int y, int val) {
	if(ly == ry) {
		if(lx == rx) tree[ndx][ndy] = val;
		else tree[ndx][ndy] = tree[ndx*2][ndy] + tree[ndx*2+1][ndy];
		return;
	} int mid = ly + ry >> 1;
	if(y <= mid) updateY(ndx, lx, rx, ndy*2, ly, mid, y, val);
	else updateY(ndx, lx, rx, ndy*2+1, mid+1, ry, y, val); 
	tree[ndx][ndy] = tree[ndx][ndy*2] + tree[ndx][ndy*2+1];
}
void updateX(int ndx, int lx, int rx, int x, int y, int val) {
	if(lx != rx) {
		int mid = lx + rx >> 1;
		if(x <= mid) updateX(ndx*2, lx, mid, x, y, val);
		else updateX(ndx*2+1, mid+1, rx, x,y, val);
	} updateY(ndx, lx, rx, 1, 0, m-1, y,val);
}

int queryY(int ndx, int ndy, int ly, int ry, int y1, int y2) {
	if(ry < y1 || ly > y2) return 0;
	if(y1 <= ly && ry <= y2) 
		return tree[ndx][ndy];
	int mid = ly + ry >> 1;
	return queryY(ndx, ndy*2, ly, mid, y1, y2) + 
		   queryY(ndx, ndy*2+1, mid+1, ry, y1, y2);
}
int queryX(int ndx, int lx, int rx, int x1, int y1, int x2, int y2) {
	if(rx < x1 || lx > x2) return 0;
	if(x1 <= lx && rx <= x2) {
		return queryY(ndx, 1, 0, m-1, y1, y2);
	} int mid = lx + rx >> 1;
	return queryX(ndx*2, lx, mid, x1,y1,x2,y2) +
		   queryX(ndx*2+1, mid+1, rx, x1,y1,x2,y2);
}
 
const int maxn = 1000;
int tree[4*maxn][4*maxn], n, m, arr[maxn][maxn];
void buildY(int ndx, int lx, int rx, int ndy, int ly, int ry) {
	if(ly == ry) {
		if(lx == rx) tree[ndx][ndy] = arr[lx][ly];
		else tree[ndx][ndy] = tree[ndx*2][ndy] + tree[ndx*2+1][ndy];
		return;
	} int mid = ly + ry >> 1;
	buildY(ndx, lx, rx, ndy*2, ly, mid);
	buildY(ndx, lx, rx, ndy*2+1, mid+1, ry);
	tree[ndx][ndy] = tree[ndx][ndy*2] + tree[ndx][ndy*2+1];
}
void buildX(int ndx, int lx, int rx) {
	if(lx != rx) {
		int mid = lx + rx >> 1;
		buildX(ndx*2, lx, mid);
		buildX(ndx*2+1, mid+1, rx);
	} buildY(ndx, lx, rx, 1, 0, m-1);
}
void updateY(int ndx, int lx, int rx, int ndy, int ly, int ry, int y, int val) {
	if(ly == ry) {
		if(lx == rx) tree[ndx][ndy] = val;
		else tree[ndx][ndy] = tree[ndx*2][ndy] + tree[ndx*2+1][ndy];
		return;
	} int mid = ly + ry >> 1;
	if(y <= mid) updateY(ndx, lx, rx, ndy*2, ly, mid, y, val);
	else updateY(ndx, lx, rx, ndy*2+1, mid+1, ry, y, val); 
	tree[ndx][ndy] = tree[ndx][ndy*2] + tree[ndx][ndy*2+1];
}
void updateX(int ndx, int lx, int rx, int x, int y, int val) {
	if(lx != rx) {
		int mid = lx + rx >> 1;
		if(x <= mid) updateX(ndx*2, lx, mid, x, y, val);
		else updateX(ndx*2+1, mid+1, rx, x,y, val);
	} updateY(ndx, lx, rx, 1, 0, m-1, y,val);
}

int queryY(int ndx, int ndy, int ly, int ry, int y1, int y2) {
	if(ry < y1 || ly > y2) return 0;
	if(y1 <= ly && ry <= y2) 
		return tree[ndx][ndy];
	int mid = ly + ry >> 1;
	return queryY(ndx, ndy*2, ly, mid, y1, y2) + 
		   queryY(ndx, ndy*2+1, mid+1, ry, y1, y2);
}
int queryX(int ndx, int lx, int rx, int x1, int y1, int x2, int y2) {
	if(rx < x1 || lx > x2) return 0;
	if(x1 <= lx && rx <= x2) {
		return queryY(ndx, 1, 0, m-1, y1, y2);
	} int mid = lx + rx >> 1;
	return queryX(ndx*2, lx, mid, x1,y1,x2,y2) +
		   queryX(ndx*2+1, mid+1, rx, x1,y1,x2,y2);
}

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 function 'void buildY(int, int, int, int, int, int)':
game.cpp:14:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  } int mid = ly + ry >> 1;
                 ^
game.cpp: In function 'void buildX(int, int, int)':
game.cpp:21:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = lx + rx >> 1;
                ^
game.cpp: In function 'void updateY(int, int, int, int, int, int, int, int)':
game.cpp:31:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  } int mid = ly + ry >> 1;
                 ^
game.cpp: In function 'void updateX(int, int, int, int, int, int)':
game.cpp:38:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = lx + rx >> 1;
                ^
game.cpp: In function 'int queryY(int, int, int, int, int, int)':
game.cpp:48:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = ly + ry >> 1;
               ^
game.cpp: In function 'int queryX(int, int, int, int, int, int, int)':
game.cpp:56:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  } int mid = lx + rx >> 1;
                 ^
game.cpp: At global scope:
game.cpp:61:11: error: redefinition of 'const int maxn'
 const int maxn = 1000;
           ^
game.cpp:7:11: note: 'const int maxn' previously defined here
 const int maxn = 2001;
           ^
game.cpp:62:24: error: redefinition of 'int tree [8004][8004]'
 int tree[4*maxn][4*maxn], n, m, arr[maxn][maxn];
                        ^
game.cpp:8:5: note: 'int tree [8004][8004]' previously declared here
 int tree[4*maxn][4*maxn], n, m, arr[maxn][maxn];
     ^
game.cpp:62:27: error: redefinition of 'int n'
 int tree[4*maxn][4*maxn], n, m, arr[maxn][maxn];
                           ^
game.cpp:8:27: note: 'int n' previously declared here
 int tree[4*maxn][4*maxn], n, m, arr[maxn][maxn];
                           ^
game.cpp:62:30: error: redefinition of 'int m'
 int tree[4*maxn][4*maxn], n, m, arr[maxn][maxn];
                              ^
game.cpp:8:30: note: 'int m' previously declared here
 int tree[4*maxn][4*maxn], n, m, arr[maxn][maxn];
                              ^
game.cpp:62:47: error: redefinition of 'int arr [2001][2001]'
 int tree[4*maxn][4*maxn], n, m, arr[maxn][maxn];
                                               ^
game.cpp:8:33: note: 'int arr [2001][2001]' previously declared here
 int tree[4*maxn][4*maxn], n, m, arr[maxn][maxn];
                                 ^
game.cpp: In function 'void buildY(int, int, int, int, int, int)':
game.cpp:63:6: error: redefinition of 'void buildY(int, int, int, int, int, int)'
 void buildY(int ndx, int lx, int rx, int ndy, int ly, int ry) {
      ^
game.cpp:9:6: note: 'void buildY(int, int, int, int, int, int)' previously defined here
 void buildY(int ndx, int lx, int rx, int ndy, int ly, int ry) {
      ^
game.cpp:68:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  } int mid = ly + ry >> 1;
                 ^
game.cpp: In function 'void buildX(int, int, int)':
game.cpp:73:6: error: redefinition of 'void buildX(int, int, int)'
 void buildX(int ndx, int lx, int rx) {
      ^
game.cpp:19:6: note: 'void buildX(int, int, int)' previously defined here
 void buildX(int ndx, int lx, int rx) {
      ^
game.cpp:75:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = lx + rx >> 1;
                ^
game.cpp: In function 'void updateY(int, int, int, int, int, int, int, int)':
game.cpp:80:6: error: redefinition of 'void updateY(int, int, int, int, int, int, int, int)'
 void updateY(int ndx, int lx, int rx, int ndy, int ly, int ry, int y, int val) {
      ^
game.cpp:26:6: note: 'void updateY(int, int, int, int, int, int, int, int)' previously defined here
 void updateY(int ndx, int lx, int rx, int ndy, int ly, int ry, int y, int val) {
      ^
game.cpp:85:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  } int mid = ly + ry >> 1;
                 ^
game.cpp: In function 'void updateX(int, int, int, int, int, int)':
game.cpp:90:6: error: redefinition of 'void updateX(int, int, int, int, int, int)'
 void updateX(int ndx, int lx, int rx, int x, int y, int val) {
      ^
game.cpp:36:6: note: 'void updateX(int, int, int, int, int, int)' previously defined here
 void updateX(int ndx, int lx, int rx, int x, int y, int val) {
      ^
game.cpp:92:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = lx + rx >> 1;
                ^
game.cpp: In function 'int queryY(int, int, int, int, int, int)':
game.cpp:98:5: error: redefinition of 'int queryY(int, int, int, int, int, int)'
 int queryY(int ndx, int ndy, int ly, int ry, int y1, int y2) {
     ^
game.cpp:44:5: note: 'int queryY(int, int, int, int, int, int)' previously defined here
 int queryY(int ndx, int ndy, int ly, int ry, int y1, int y2) {
     ^
game.cpp:102:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = ly + ry >> 1;
               ^
game.cpp: In function 'int queryX(int, int, int, int, int, int, int)':
game.cpp:106:5: error: redefinition of 'int queryX(int, int, int, int, int, int, int)'
 int queryX(int ndx, int lx, int rx, int x1, int y1, int x2, int y2) {
     ^
game.cpp:52:5: note: 'int queryX(int, int, int, int, int, int, int)' previously defined here
 int queryX(int ndx, int lx, int rx, int x1, int y1, int x2, int y2) {
     ^
game.cpp:110:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  } int mid = lx + rx >> 1;
                 ^