Submission #119796

# Submission time Handle Problem Language Result Execution time Memory
119796 2019-06-22T11:23:58 Z nvmdava Game (IOI13_game) C++17
Compilation error
0 ms 0 KB
//#include "game.h"
#include <bits/stdc++.h>
using namespace std;
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{
   int x1, x2, y1, y2;
   long long gcd = 0;
   Node *t[2][2] = {{NULL}};

   Node(int _x1, int _y1, int _x2, int _y2){
      x1 = _x1;
      y1 = _y1;
      x2 = _x2;
      y2 = _y2;
   }

   void create(){
      if(t[0][0] != NULL) return;
      int mx = (x1 + x2) >> 1;
      int my = (y1 + y2) >> 1;
      t[0][0] = new Node(x1, y1, mx, my);
      t[1][0] = new Node(mx + 1, y1, x2, my);
      t[0][1] = new Node(x1, my + 1, mx, y2);
      t[1][1] = new Node(mx + 1, my + 1, x2, y2);
   }

   void update(int x, int y, long long val){
      if(x1 == x2 && y1 == y2){
         gcd = val;
         return;
      }
      create();
      int mx = (x1 + x2) >> 1;
      int my = (y1 + y2) >> 1;
      if(x <= mx && y <= my)
         t[0][0] -> update(x, y, val);
      if(x > mx && y <= my)
         t[1][0] -> update(x, y, val);
      if(x <= mx && y > my)
         t[0][1] -> update(x, y, val);
      if(x > mx && y > my)
         t[1][1] -> update(x, y, val);

      gcd = gcd2(gcd2(t[0][0] -> gcd, t[1][1] -> gcd), gcd2(t[0][1] -> gcd, t[1][0] -> gcd));
   }

   long long query(int qx1, int qy1, int qx2, int qy2){
      cerr<<x1<<' '<<y1<<' '<<x2<<' '<<y2<<'\n';
      if(qx1 > x2 || qy1 > y2 || qy2 < y1 || qx2 < x1) return 0;
      if(gcd == 0) return 0;
      if(qx1 <= x1 && qx2 >= x2 && qy1 <= y1 && qy2 >= y2) return gcd;
      return gcd2(gcd2(t[0][0] -> query(qx1, qy1, qx2, qy2), t[0][1] -> query(qx1, qy1, qx2, qy2)), gcd2(t[1][0] -> query(qx1, qy1, qx2, qy2), t[1][1] -> query(qx1, qy1, qx2, qy2)));
   }
} *root;


void init(int R, int C) {
   root = new Node(0, 0, 2047, 2047);
}

void update(int P, int Q, long long K) {
   root -> update(P, Q, K);
}

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

#define MAX_SIZE 1000000000
#define MAX_N 272000

int main() {
	int R, C, N;
    int P, Q, U, V;
    long long K;
    int i, type;
	int res;

	scanf("%d", &R);
	scanf("%d", &C);
	scanf("%d", &N);

   init(R, C);

	for (i = 0; i < N; i++) {
        scanf("%d", &type);
        if (type == 1) {
		    scanf("%d%d%lld", &P, &Q, &K);
            update(P, Q, K);
        } else if (type == 2) {
		    scanf("%d%d%d%d", &P, &Q, &U, &V);
            printf("%lld\n", calculate(P, Q, U, V));
        }
	}
	return 0;
}

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 'int main()':
game.cpp:86:6: warning: unused variable 'res' [-Wunused-variable]
  int res;
      ^~~
game.cpp:88:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &R);
  ~~~~~^~~~~~~~~~
game.cpp:89:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &C);
  ~~~~~^~~~~~~~~~
game.cpp:90:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
game.cpp:95:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &type);
         ~~~~~^~~~~~~~~~~~~
game.cpp:97:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d%d%lld", &P, &Q, &K);
       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
game.cpp:100:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d%d%d%d", &P, &Q, &U, &V);
       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/ccccOm0V.o: In function `main':
game.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccQYEFJ1.o:grader.c:(.text.startup+0x0): first defined here
/tmp/ccQYEFJ1.o: In function `main':
grader.c:(.text.startup+0x5d): undefined reference to `init'
grader.c:(.text.startup+0xb8): undefined reference to `calculate'
grader.c:(.text.startup+0x122): undefined reference to `update'
collect2: error: ld returned 1 exit status