Submission #281809

# Submission time Handle Problem Language Result Execution time Memory
281809 2020-08-23T13:54:28 Z amoo_safar Game (IOI13_game) C++17
63 / 100
2281 ms 256004 KB
#include "game.h"

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int Inf = 1e9 + 3;

struct Seg {
    ll g;
    Seg *lc, *rc;
    Seg (){
        g = 0;
        lc = NULL;
        rc = NULL;
    }
    void Set(int idx, ll val, int L, int R){
        if(L + 1 == R){
            g = val;
            return ;
        }
        int mid = (L + R) >> 1;
        if(idx < mid){
            if(!lc) lc = new Seg();
            lc -> Set(idx, val, L, mid);
        } else {
            if(!rc) rc = new Seg();
            rc -> Set(idx, val, mid, R);
        }
        g = __gcd(lc ? lc -> g : 0, rc ? rc -> g : 0);
    }
    ll Get(int l, int r, int L, int R){
        if(r <= L || R <= l) return 0;
        if(l <= L && R <= r) return g;
        int mid = (L + R) >> 1;
        return __gcd(lc ? lc -> Get(l, r, L, mid) : 0, rc ? rc -> Get(l, r, mid, R) : 0);
    }
    void Update(Seg *hl, Seg *hr, int idx, int L, int R){
        if(L + 1 == R){
            g = __gcd(hl ? hl -> g : 0, hr ? hr -> g : 0);
            return ;
        }
        int mid = (L + R) >> 1;
        if(idx < mid){
            if(!lc) lc = new Seg();
            lc -> Update(hl ? hl -> lc : NULL, hr ? hr -> lc : NULL, idx, L, mid);
        } else {
            if(!rc) rc = new Seg();
            rc -> Update(hl ? hl -> rc : NULL, hr ? hr -> rc : NULL, idx, mid, R);
        }
        g = __gcd(lc ? lc -> g : 0, rc ? rc -> g : 0);
    }
};

struct Seg2D {
    Seg *ds;
    Seg2D *lc, *rc;
    Seg2D (){
        ds = new Seg();
        lc = NULL;
        rc = NULL;
    }
    void Set(int x, int y, ll val, int L, int R){
        if(L + 1 == R){
            ds -> Set(y, val, 0, Inf);
            return ;
        }
        int mid = (L + R) >> 1;
        if(x < mid){
            if(!lc) lc = new Seg2D();
            lc -> Set(x, y, val, L, mid);
        } else {
            if(!rc) rc = new Seg2D();
            rc -> Set(x, y, val, mid, R);
        }
        ds -> Update(lc ? lc -> ds : NULL, rc ? rc -> ds : NULL, y, 0, Inf);
    }
    ll Get(int lx, int rx, int ly, int ry, int L, int R){
        if(rx <= L || R <= lx) return 0;
        if(lx <= L && R <= rx) return ds -> Get(ly, ry, 0, Inf);
        int mid = (L + R) >> 1;
        return __gcd(lc ? lc -> Get(lx, rx, ly, ry, L, mid) : 0, rc ? rc -> Get(lx, rx, ly, ry, mid, R) : 0);
    }
};
Seg2D Board;

void init(int R, int C) {
    assert(R <= Inf);
    assert(C <= Inf);
}

void update(int P, int Q, ll K) {
    Board.Set(P, Q, K, 0, Inf);
}

ll calculate(int P, int Q, int U, int V) {
    return Board.Get(P, U + 1, Q, V + 1, 0, Inf);
}

Compilation message

grader.c: In function 'int main()':
grader.c:18:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   18 |  int res;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 923 ms 52532 KB Output is correct
5 Correct 750 ms 52728 KB Output is correct
6 Correct 887 ms 50084 KB Output is correct
7 Correct 953 ms 49884 KB Output is correct
8 Correct 610 ms 31436 KB Output is correct
9 Correct 939 ms 49912 KB Output is correct
10 Correct 952 ms 49528 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1128 ms 21368 KB Output is correct
13 Correct 1492 ms 11808 KB Output is correct
14 Correct 455 ms 3892 KB Output is correct
15 Correct 1776 ms 16508 KB Output is correct
16 Correct 523 ms 26232 KB Output is correct
17 Correct 1371 ms 19064 KB Output is correct
18 Correct 2281 ms 26488 KB Output is correct
19 Correct 1905 ms 26872 KB Output is correct
20 Correct 1807 ms 26104 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 915 ms 52436 KB Output is correct
13 Correct 675 ms 52600 KB Output is correct
14 Correct 949 ms 50040 KB Output is correct
15 Correct 973 ms 49776 KB Output is correct
16 Correct 669 ms 31536 KB Output is correct
17 Correct 995 ms 50032 KB Output is correct
18 Correct 966 ms 49408 KB Output is correct
19 Correct 1153 ms 21848 KB Output is correct
20 Correct 1526 ms 11768 KB Output is correct
21 Correct 467 ms 3960 KB Output is correct
22 Correct 1902 ms 16156 KB Output is correct
23 Correct 518 ms 26160 KB Output is correct
24 Correct 1333 ms 19064 KB Output is correct
25 Correct 2230 ms 26456 KB Output is correct
26 Correct 1963 ms 26816 KB Output is correct
27 Correct 1798 ms 25128 KB Output is correct
28 Correct 1117 ms 253176 KB Output is correct
29 Runtime error 1922 ms 256004 KB Execution killed with signal 9
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 3 ms 800 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 915 ms 52728 KB Output is correct
13 Correct 684 ms 52768 KB Output is correct
14 Correct 906 ms 49588 KB Output is correct
15 Correct 1004 ms 49400 KB Output is correct
16 Correct 642 ms 31224 KB Output is correct
17 Correct 978 ms 49656 KB Output is correct
18 Correct 909 ms 49144 KB Output is correct
19 Correct 1143 ms 21176 KB Output is correct
20 Correct 1538 ms 11296 KB Output is correct
21 Correct 464 ms 3448 KB Output is correct
22 Correct 1817 ms 15832 KB Output is correct
23 Correct 501 ms 25720 KB Output is correct
24 Correct 1314 ms 18664 KB Output is correct
25 Correct 2247 ms 26104 KB Output is correct
26 Correct 1898 ms 26360 KB Output is correct
27 Correct 1839 ms 25760 KB Output is correct
28 Correct 1085 ms 253944 KB Output is correct
29 Runtime error 1916 ms 256000 KB Execution killed with signal 9
30 Halted 0 ms 0 KB -