Submission #437289

# Submission time Handle Problem Language Result Execution time Memory
437289 2021-06-26T06:47:25 Z Mackerel_Pike Game (IOI13_game) C++14
63 / 100
1838 ms 162248 KB
#include "game.h"
#include <bits/stdc++.h>

typedef long long ll;

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;
}

class SegmentTree{
public:
  static const int maxv = 1e6 + 5;
  static const int maxv2 = 5e6 + 5;
  static const int siz = 1000000000;
  int tot, tot2, r;
  int ls[maxv], rs[maxv], rt[maxv];
  int ls2[maxv2], rs2[maxv2];
  ll dat[maxv2];
  inline void init(){ r = 0, tot = tot2 = 1; return; }
  inline void update2(int q, ll k, int &u, int l = 0, int r = siz - 1){
    if(!u)
      u = tot2++, dat[u] = 0;
    //printf("update2 u = %d l = %d r = %d\n", u, l, r);
    if(l == r){
      dat[u] = k;
      return;
    }
    int md = l + r >> 1;
    if(q <= md)
      update2(q, k, ls2[u], l, md);
    else
      update2(q, k, rs2[u], md + 1, r);
    dat[u] = gcd2(dat[ls2[u]], dat[rs2[u]]);
    return;
  }

  inline void pushUp(int q, int &v, int vl, int vr, int l = 0, int r = siz - 1){
    if(!vl && !vr)
      return;
    if(!v)
      v = tot2++, dat[v] = 0;
    if(l == r){
      dat[v] = gcd2(dat[vl], dat[vr]);
      return;
    }
    int md = l + r >> 1;
    if(q <= md)
      pushUp(q, ls2[v], ls2[vl], ls2[vr], l, md);
    else
      pushUp(q, rs2[v], rs2[vl], rs2[vr], md + 1, r);
    dat[v] = gcd2(dat[ls2[v]], dat[rs2[v]]);
    return;
  }
  
  inline void update(int p, int q, ll k, int &u, int l = 0, int r = siz - 1){
    if(!u)
      u = tot++;
    //printf("update u = %d rt = %d\n", u, rt[u]);
    if(l == r){
      update2(q, k, rt[u]);
      return;
    }
    int md = l + r >> 1;
    if(p <= md)
      update(p, q, k, ls[u], l, md);
    else
      update(p, q, k, rs[u], md + 1, r);
    pushUp(q, rt[u], rt[ls[u]], rt[rs[u]]);
    return;
  }

  inline ll query2(int s, int t, int u, int l = 0, int r = siz - 1){
    //printf("query2 u = %d\n", u);
    if(!u){
      return 0;
    }
    if(l >= s && r <= t){
      return dat[u];
    }
    int md = l + r >> 1;
    if(s > md)
      return query2(s, t, rs2[u], md + 1, r);
    if(t <= md)
      return query2(s, t, ls2[u], l, md);
    return gcd2(query2(s, t, ls2[u], l, md), query2(s, t, rs2[u], md + 1, r));
  }

  inline ll query(int p, int q, int s, int t, int u, int l = 0, int r = siz - 1){
    if(!u)
      return 0;
    if(l >= p && r <= q)
      return query2(s, t, rt[u]);
    int md = l + r >> 1;
    if(p > md)
      return query(p, q, s, t, rs[u], md + 1, r);
    if(q <= md)
      return query(p, q, s, t, ls[u], l, md);
    return gcd2(query(p, q, s, t, rs[u], md + 1, r), query(p, q, s, t, ls[u], l, md));
  }
} seg;

void init(int R, int C) {
  seg.init();
}

void update(int P, int Q, long long K) {
  seg.update(P, Q, K, seg.r);
  return;
}

long long calculate(int P, int Q, int U, int V) {
  return seg.query(P, U, Q, V, seg.r);
}

Compilation message

game.cpp: In member function 'void SegmentTree::update2(int, ll, int&, int, int)':
game.cpp:34:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   34 |     int md = l + r >> 1;
      |              ~~^~~
game.cpp: In member function 'void SegmentTree::pushUp(int, int&, int, int, int, int)':
game.cpp:52:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   52 |     int md = l + r >> 1;
      |              ~~^~~
game.cpp: In member function 'void SegmentTree::update(int, int, ll, int&, int, int)':
game.cpp:69:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   69 |     int md = l + r >> 1;
      |              ~~^~~
game.cpp: In member function 'll SegmentTree::query2(int, int, int, int, int)':
game.cpp:86:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   86 |     int md = l + r >> 1;
      |              ~~^~~
game.cpp: In member function 'll SegmentTree::query(int, int, int, int, int, int, int)':
game.cpp:99:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   99 |     int md = l + r >> 1;
      |              ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 3 ms 460 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 653 ms 27312 KB Output is correct
5 Correct 497 ms 27448 KB Output is correct
6 Correct 698 ms 24428 KB Output is correct
7 Correct 771 ms 24252 KB Output is correct
8 Correct 502 ms 15388 KB Output is correct
9 Correct 718 ms 24476 KB Output is correct
10 Correct 679 ms 24124 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 2 ms 404 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 927 ms 11456 KB Output is correct
13 Correct 1323 ms 5080 KB Output is correct
14 Correct 414 ms 1152 KB Output is correct
15 Correct 1523 ms 7364 KB Output is correct
16 Correct 444 ms 12344 KB Output is correct
17 Correct 964 ms 8924 KB Output is correct
18 Correct 1838 ms 12688 KB Output is correct
19 Correct 1434 ms 12860 KB Output is correct
20 Correct 1338 ms 12100 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 702 ms 27328 KB Output is correct
13 Correct 512 ms 27476 KB Output is correct
14 Correct 662 ms 24352 KB Output is correct
15 Correct 754 ms 24124 KB Output is correct
16 Correct 443 ms 15288 KB Output is correct
17 Correct 769 ms 24388 KB Output is correct
18 Correct 667 ms 23960 KB Output is correct
19 Correct 949 ms 11512 KB Output is correct
20 Correct 1361 ms 4904 KB Output is correct
21 Correct 401 ms 944 KB Output is correct
22 Correct 1554 ms 7200 KB Output is correct
23 Correct 400 ms 12188 KB Output is correct
24 Correct 969 ms 8952 KB Output is correct
25 Correct 1628 ms 12596 KB Output is correct
26 Correct 1388 ms 12564 KB Output is correct
27 Correct 1277 ms 11952 KB Output is correct
28 Runtime error 453 ms 162196 KB Execution killed with signal 11
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 3 ms 460 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 687 ms 27436 KB Output is correct
13 Correct 518 ms 27480 KB Output is correct
14 Correct 724 ms 24432 KB Output is correct
15 Correct 721 ms 24132 KB Output is correct
16 Correct 484 ms 15496 KB Output is correct
17 Correct 832 ms 24452 KB Output is correct
18 Correct 700 ms 23932 KB Output is correct
19 Correct 954 ms 11468 KB Output is correct
20 Correct 1315 ms 5096 KB Output is correct
21 Correct 395 ms 1092 KB Output is correct
22 Correct 1633 ms 7284 KB Output is correct
23 Correct 409 ms 12100 KB Output is correct
24 Correct 892 ms 8988 KB Output is correct
25 Correct 1652 ms 12480 KB Output is correct
26 Correct 1528 ms 12768 KB Output is correct
27 Correct 1306 ms 12048 KB Output is correct
28 Runtime error 517 ms 162248 KB Execution killed with signal 11
29 Halted 0 ms 0 KB -