답안 #516562

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
516562 2022-01-21T13:21:35 Z kripton2005 게임 (IOI13_game) C++14
100 / 100
2775 ms 81980 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;
}
typedef long long ll;
int n,m;
struct nodex {
  int st,dr;
  nodex *fiust,*fiudr;
  long long val;
  nodex(int stanga,int dreapta) {
    st=stanga;
    dr=dreapta;
    val=0;
    fiust=fiudr=nullptr;
  }
};
struct nodey {
  nodey(int stanga,int dreapta) : st(stanga), dr(dreapta), fiust(NULL), fiudr(NULL), fiux(1,m) {}
  int st,dr;
  nodex fiux;
  nodey *fiust,*fiudr;
}*root;
ll query2(nodex *arb, int st,int dr) {
  if (arb == nullptr || arb->st>dr||st>arb->dr) {
    return 0;
  }
  if (st<=arb->st&&arb->dr<=dr) {
    return arb->val;
  }
  int mij=(arb->st+arb->dr)/2;
  return gcd2(
           query2(arb->fiust,st,dr),
           query2(arb->fiudr,st,dr)
         );
}
ll query1(nodey *arb,int st,int dr,int p,int q,int u,int v) {
  if (arb == NULL || st > u || dr<p) {
    return 0;
  }
  if (p<=st && dr<=u) {
    return query2(&arb->fiux,q,v);
  }
  int mij=(st+dr)/2;
  return gcd2(
           query1(arb->fiust,st,mij,p,q,u,v),
           query1(arb->fiudr,mij+1,dr,p,q,u,v)
         );
}
void init(int R, int C) {
  n=R;
  m=C;
  root = new nodey(1,n);
}
void updatey(nodex *arb,int y,ll k) {
  int st = arb->st, dr = arb->dr, mij=(st+dr)/2;
  if (st==dr) {
    arb->val=k;
    return;
  }
  nodex **copil = &(y<=mij ? arb->fiust : arb->fiudr);
  if (*copil == NULL) {
    *copil = new nodex (y,y);
    (*copil)->val = k;
  } else if ((*copil)->st<=y&&y<=(*copil)->dr) {
    updatey(*copil,y,k);
  } else {
    do {
      if (y<=mij) {
        dr=mij;
      } else {
        st=mij+1;
      }
      mij=(st+dr)/2;
    } while ((y<=mij) == ((*copil)->dr<=mij));
    nodex *nnode = new nodex(st,dr);

    bool ok=(y<(*copil)->st);

    if ((*copil)->dr<=mij) {
      assert(!ok);
      nnode->fiust = *copil;
    } else {
      assert(ok);
      nnode->fiudr = *copil;
    }
    *copil=nnode;

    updatey(*copil,y,k);
  }
  arb->val = gcd2(
               arb->fiust ? arb->fiust->val : 0,
               arb->fiudr ? arb->fiudr->val : 0
             );
}
void updatex(nodey *arb, int st,int dr,int x,int y,long long k) {
  int mij=(st+dr)/2;
  if (st==dr) {
    updatey(&arb->fiux,y,k);
    return;
  }
  if (x<=mij) {
    if (arb->fiust==NULL) {
      arb->fiust=new nodey(st,mij);
    }
    updatex(arb->fiust,st,mij,x,y,k);
  } else {
    if (arb->fiudr==NULL) {
      arb->fiudr= new nodey(mij+1,dr);
    }
    updatex(arb->fiudr,mij+1,dr,x,y,k);
  }
  ll val = gcd2(
             arb->fiust ? query2(&arb->fiust->fiux,y,y) : 0,
             arb->fiudr ? query2(&arb->fiudr->fiux,y,y) : 0
           );
  updatey(&arb->fiux,y,val);
}
void update(int P, int Q, long long K) {
  P++;
  Q++;
  updatex(root,1,n,P,Q,K);
}
long long calculate(int P, int Q, int U, int V) {
  P++;
  Q++;
  U++;
  V++;
  return query1(root,1,n,P,Q,U,V);
}

Compilation message

game.cpp: In constructor 'nodey::nodey(int, int)':
game.cpp:31:17: warning: 'nodey::fiudr' will be initialized after [-Wreorder]
   31 |   nodey *fiust,*fiudr;
      |                 ^~~~~
game.cpp:30:9: warning:   'nodex nodey::fiux' [-Wreorder]
   30 |   nodex fiux;
      |         ^~~~
game.cpp:28:3: warning:   when initialized here [-Wreorder]
   28 |   nodey(int stanga,int dreapta) : st(stanga), dr(dreapta), fiust(NULL), fiudr(NULL), fiux(1,m) {}
      |   ^~~~~
game.cpp: In function 'll query2(nodex*, int, int)':
game.cpp:40:7: warning: unused variable 'mij' [-Wunused-variable]
   40 |   int mij=(arb->st+arb->dr)/2;
      |       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 413 ms 8320 KB Output is correct
5 Correct 280 ms 8568 KB Output is correct
6 Correct 358 ms 5284 KB Output is correct
7 Correct 519 ms 5188 KB Output is correct
8 Correct 267 ms 3776 KB Output is correct
9 Correct 392 ms 5224 KB Output is correct
10 Correct 355 ms 4740 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 659 ms 11428 KB Output is correct
13 Correct 1258 ms 4968 KB Output is correct
14 Correct 207 ms 876 KB Output is correct
15 Correct 1415 ms 6024 KB Output is correct
16 Correct 164 ms 9796 KB Output is correct
17 Correct 542 ms 6304 KB Output is correct
18 Correct 978 ms 10308 KB Output is correct
19 Correct 838 ms 10376 KB Output is correct
20 Correct 773 ms 9780 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 400 ms 8328 KB Output is correct
13 Correct 296 ms 8612 KB Output is correct
14 Correct 360 ms 5288 KB Output is correct
15 Correct 405 ms 5152 KB Output is correct
16 Correct 262 ms 3744 KB Output is correct
17 Correct 397 ms 5260 KB Output is correct
18 Correct 345 ms 4740 KB Output is correct
19 Correct 670 ms 11512 KB Output is correct
20 Correct 1253 ms 5044 KB Output is correct
21 Correct 221 ms 836 KB Output is correct
22 Correct 1392 ms 6068 KB Output is correct
23 Correct 167 ms 9924 KB Output is correct
24 Correct 540 ms 6084 KB Output is correct
25 Correct 978 ms 10188 KB Output is correct
26 Correct 823 ms 10232 KB Output is correct
27 Correct 743 ms 9748 KB Output is correct
28 Correct 364 ms 34124 KB Output is correct
29 Correct 1079 ms 45308 KB Output is correct
30 Correct 1964 ms 35356 KB Output is correct
31 Correct 1764 ms 28604 KB Output is correct
32 Correct 306 ms 10192 KB Output is correct
33 Correct 401 ms 10664 KB Output is correct
34 Correct 218 ms 39208 KB Output is correct
35 Correct 727 ms 26824 KB Output is correct
36 Correct 1536 ms 43224 KB Output is correct
37 Correct 1168 ms 43396 KB Output is correct
38 Correct 1140 ms 43016 KB Output is correct
39 Correct 952 ms 35780 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 412 ms 8352 KB Output is correct
13 Correct 286 ms 8604 KB Output is correct
14 Correct 349 ms 5384 KB Output is correct
15 Correct 410 ms 5096 KB Output is correct
16 Correct 263 ms 3780 KB Output is correct
17 Correct 383 ms 5260 KB Output is correct
18 Correct 350 ms 4804 KB Output is correct
19 Correct 676 ms 11520 KB Output is correct
20 Correct 1261 ms 5068 KB Output is correct
21 Correct 214 ms 892 KB Output is correct
22 Correct 1385 ms 6160 KB Output is correct
23 Correct 168 ms 9796 KB Output is correct
24 Correct 549 ms 6212 KB Output is correct
25 Correct 1088 ms 10128 KB Output is correct
26 Correct 872 ms 10416 KB Output is correct
27 Correct 765 ms 9696 KB Output is correct
28 Correct 348 ms 33988 KB Output is correct
29 Correct 1045 ms 45328 KB Output is correct
30 Correct 2008 ms 35072 KB Output is correct
31 Correct 1868 ms 28484 KB Output is correct
32 Correct 332 ms 10140 KB Output is correct
33 Correct 415 ms 10820 KB Output is correct
34 Correct 276 ms 39052 KB Output is correct
35 Correct 762 ms 26864 KB Output is correct
36 Correct 1644 ms 43180 KB Output is correct
37 Correct 1291 ms 43388 KB Output is correct
38 Correct 1267 ms 42748 KB Output is correct
39 Correct 602 ms 81060 KB Output is correct
40 Correct 1810 ms 81980 KB Output is correct
41 Correct 2775 ms 67144 KB Output is correct
42 Correct 2484 ms 52460 KB Output is correct
43 Correct 418 ms 76752 KB Output is correct
44 Correct 372 ms 10620 KB Output is correct
45 Correct 947 ms 35656 KB Output is correct
46 Correct 2084 ms 81012 KB Output is correct
47 Correct 2094 ms 80976 KB Output is correct
48 Correct 2069 ms 80460 KB Output is correct
49 Correct 1 ms 204 KB Output is correct