Submission #1016118

# Submission time Handle Problem Language Result Execution time Memory
1016118 2024-07-07T12:06:41 Z huutuan Game (IOI13_game) C++14
100 / 100
1703 ms 87728 KB
#include "game.h"

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

#include <assert.h>

int R, C;

struct Node{
   long long val;
   Node *l;
   Node *r;
   int lv, rv;
   Node (int _lv, int _rv){
      val=0;
      l=nullptr;
      r=nullptr;
      lv=_lv, rv=_rv;
   }
};

struct SegmentTree{
   Node *root;
   SegmentTree *l;
   SegmentTree *r;
   SegmentTree(){
      root=new Node(1, 1e9);
      l=nullptr;
      r=nullptr;
   }
   void update(Node *t, int pos, long long val){
      int l=t->lv, r=t->rv;
      if (l==r){
         t->val=val;
         return;
      }
      int mid=(l+r)>>1;
      Node *&tt=pos<=mid?t->l:t->r;
      if (!tt){
         tt=new Node(pos, pos);
         tt->val=val;
      }else if (tt->lv<=pos && pos<=tt->rv){
         update(tt, pos, val);
      }else{
         do{
            if (pos<=mid) r=mid;
            else l=mid+1;
            mid=(l+r)>>1;
         }while ((pos<=mid)==(tt->lv<=mid));
         Node *tmp=new Node(l, r);
         (tt->lv<=mid?tmp->l:tmp->r)=tt;
         tt=tmp;
         update(tmp, pos, val);
      }
      t->val=gcd2(t->l?t->l->val:0, t->r?t->r->val:0);
   }
   long long get(Node *t, int L, int R){
      int l=t->lv, r=t->rv;
      if (r<L || R<l) return 0;
      if (L<=l && r<=R) return t->val;
      return gcd2(t->l?get(t->l, L, R):0, t->r?get(t->r, L, R):0);
   }
};

struct SegmentTree2d{
   SegmentTree *root;
   SegmentTree2d(){
      root=new SegmentTree();
   }
   void update(SegmentTree *t, int l, int r, int x, int y, long long val){
      if (l!=r){
         int mid=(l+r)>>1;
         if (x<=mid){
            if (!t->l) t->l=new SegmentTree();
            update(t->l, l, mid, x, y, val);
         }else{
            if (!t->r) t->r=new SegmentTree();
            update(t->r, mid+1, r, x, y, val);
         }
         val=gcd2(t->l?t->l->get(t->l->root, y, y):0, t->r?t->r->get(t->r->root, y, y):0);
      }
      t->update(t->root, y, val);
   }
   long long get(SegmentTree *t, int l, int r, int lx, int rx, int ly, int ry){
      if (rx<l || r<lx) return 0;
      if (lx<=l && r<=rx) return t->get(t->root, ly, ry);
      int mid=(l+r)>>1;
      return gcd2(t->l?get(t->l, l, mid, lx, rx, ly, ry):0, t->r?get(t->r, mid+1, r, lx, rx, ly, ry):0);
   }
} st;

void init(int _R, int _C) {
   R=_R; C=_C;
}

void update(int P, int Q, long long K) {
   ++P; ++Q;
   st.update(st.root, 1, 1e9, P, Q, K);
}

long long calculate(int P, int Q, int U, int V) {
   ++P; ++Q; ++U; ++V;
   return st.get(st.root, 1, 1e9, P, U, Q, V);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 2 ms 612 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 373 ms 32216 KB Output is correct
5 Correct 253 ms 36260 KB Output is correct
6 Correct 442 ms 34000 KB Output is correct
7 Correct 552 ms 33620 KB Output is correct
8 Correct 278 ms 19792 KB Output is correct
9 Correct 474 ms 33532 KB Output is correct
10 Correct 465 ms 33440 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 424 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 479 ms 17656 KB Output is correct
13 Correct 690 ms 10908 KB Output is correct
14 Correct 167 ms 5712 KB Output is correct
15 Correct 821 ms 13904 KB Output is correct
16 Correct 187 ms 18004 KB Output is correct
17 Correct 492 ms 14480 KB Output is correct
18 Correct 858 ms 19284 KB Output is correct
19 Correct 739 ms 19524 KB Output is correct
20 Correct 719 ms 19056 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 412 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 424 KB Output is correct
12 Correct 372 ms 36432 KB Output is correct
13 Correct 238 ms 36176 KB Output is correct
14 Correct 421 ms 33888 KB Output is correct
15 Correct 453 ms 33708 KB Output is correct
16 Correct 272 ms 19792 KB Output is correct
17 Correct 437 ms 33616 KB Output is correct
18 Correct 429 ms 33408 KB Output is correct
19 Correct 455 ms 18000 KB Output is correct
20 Correct 705 ms 10836 KB Output is correct
21 Correct 157 ms 5712 KB Output is correct
22 Correct 714 ms 13904 KB Output is correct
23 Correct 202 ms 17868 KB Output is correct
24 Correct 584 ms 14416 KB Output is correct
25 Correct 823 ms 19540 KB Output is correct
26 Correct 785 ms 19536 KB Output is correct
27 Correct 648 ms 19032 KB Output is correct
28 Correct 291 ms 45904 KB Output is correct
29 Correct 740 ms 48204 KB Output is correct
30 Correct 1174 ms 36616 KB Output is correct
31 Correct 1110 ms 29584 KB Output is correct
32 Correct 212 ms 10320 KB Output is correct
33 Correct 268 ms 10876 KB Output is correct
34 Correct 205 ms 41956 KB Output is correct
35 Correct 536 ms 28476 KB Output is correct
36 Correct 1088 ms 46112 KB Output is correct
37 Correct 871 ms 46156 KB Output is correct
38 Correct 822 ms 45652 KB Output is correct
39 Correct 709 ms 37940 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 564 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 360 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 405 ms 36460 KB Output is correct
13 Correct 228 ms 36324 KB Output is correct
14 Correct 424 ms 33904 KB Output is correct
15 Correct 544 ms 33616 KB Output is correct
16 Correct 286 ms 19792 KB Output is correct
17 Correct 461 ms 33684 KB Output is correct
18 Correct 437 ms 33360 KB Output is correct
19 Correct 414 ms 17956 KB Output is correct
20 Correct 706 ms 10996 KB Output is correct
21 Correct 159 ms 5736 KB Output is correct
22 Correct 805 ms 14068 KB Output is correct
23 Correct 200 ms 18024 KB Output is correct
24 Correct 531 ms 14392 KB Output is correct
25 Correct 893 ms 19712 KB Output is correct
26 Correct 772 ms 19460 KB Output is correct
27 Correct 760 ms 18860 KB Output is correct
28 Correct 269 ms 45936 KB Output is correct
29 Correct 737 ms 48244 KB Output is correct
30 Correct 1176 ms 36792 KB Output is correct
31 Correct 1230 ms 29760 KB Output is correct
32 Correct 211 ms 10252 KB Output is correct
33 Correct 277 ms 10692 KB Output is correct
34 Correct 165 ms 41808 KB Output is correct
35 Correct 576 ms 28496 KB Output is correct
36 Correct 1042 ms 46160 KB Output is correct
37 Correct 804 ms 46164 KB Output is correct
38 Correct 843 ms 45656 KB Output is correct
39 Correct 360 ms 86912 KB Output is correct
40 Correct 1304 ms 87728 KB Output is correct
41 Correct 1703 ms 70300 KB Output is correct
42 Correct 1551 ms 54868 KB Output is correct
43 Correct 309 ms 82456 KB Output is correct
44 Correct 247 ms 10848 KB Output is correct
45 Correct 712 ms 37972 KB Output is correct
46 Correct 1387 ms 86608 KB Output is correct
47 Correct 1420 ms 86700 KB Output is correct
48 Correct 1432 ms 86180 KB Output is correct
49 Correct 1 ms 344 KB Output is correct