Submission #1075890

# Submission time Handle Problem Language Result Execution time Memory
1075890 2024-08-26T09:38:58 Z mc061 Game (IOI13_game) C++17
37 / 100
2403 ms 256000 KB
#pragma once

#include <bits/stdc++.h>
#include "game.h"
using namespace std;

const int SZ = 1e9+1;

struct smallnode {
    long long ans;
    int left, right;
    smallnode() {
        ans = 0, left = -1, right = -1;
    }
};
smallnode smalls[1<<23];
int nxt_free = 0;
int create() {
    smalls[nxt_free] = smallnode();
    return nxt_free++;
}

struct bignode {
    int left, right;
    int root;
    bignode() {
        root = -1, left = -1, right = -1;
    }
    void update(int idx, long long val, int x = 0, int tl = 0, int tr = SZ) {
        if (tl == tr) {
            smalls[x].ans = val;
            return;
        }
        int m = (tl + tr) >> 1;
        if (idx <= m) {
            if (smalls[x].left == -1) {
                smalls[x].left = create();
            }
            update(idx, val, smalls[x].left, tl, m);
        }
        else {
            if (smalls[x].right == -1) {
                smalls[x].right = create();
            }
            update(idx, val, smalls[x].right, m+1, tr);
        }
        smalls[x].ans = (smalls[x].left == -1 ? 0 : smalls[smalls[x].left].ans);
        smalls[x].ans = __gcd(smalls[x].ans, (smalls[x].right == -1 ? 0 : smalls[smalls[x].right].ans));
    }
    long long query(int l, int r, int x = 0, int tl = 0, int tr = SZ) {
        if (tl >= l && tr <= r) return smalls[x].ans;
        if (tr < l || tl > r) return 0;
        int m = (tl + tr) >> 1;
        long long from_r = (smalls[x].right == -1 ? 0 : query(l, r, smalls[x].right, m+1, tr));
        long long from_l = (smalls[x].left == -1 ? 0 : query(l, r, smalls[x].left, tl, m));
        return __gcd(from_l, from_r);
    }
};
bignode bigs[1<<10];
int nxt_free_big = 0;
int create_big() {
    bigs[nxt_free_big] = bignode();
    bigs[nxt_free_big].root = create();
    return nxt_free_big++;
}

struct segtree {
    void update(int i, int j, long long val, int x = 0, int tl = 0, int tr = SZ) {
        if (tl == tr) {
            bigs[x].update(j, val, bigs[x].root);
            return;
        }
        int m = (tl + tr) >> 1;
        if (i <= m) {
            if (bigs[x].left == -1) {
                bigs[x].left = create_big();
            }
            update(i, j, val, bigs[x].left, tl, m);
        }
        else {
            if (bigs[x].right == -1) {
                bigs[x].right = create_big();
            }
            update(i, j, val, bigs[x].right, m+1, tr);
        }
        long long from_l = (bigs[x].left == -1 ? 0 : bigs[bigs[x].left].query(j, j, bigs[bigs[x].left].root));
        long long from_r = (bigs[x].right == -1 ? 0 : bigs[bigs[x].right].query(j, j, bigs[bigs[x].right].root));
        bigs[x].update(j, __gcd(from_l, from_r), bigs[x].root);
    }
    long long query(int l, int r, int jl, int jr, int x = 0, int tl = 0, int tr = SZ) {
        if (tl >= l && tr <= r) {
            return bigs[x].query(jl, jr, bigs[x].root);
        }
        if (tl > r || l > tr) return 0;
        int m = (tl + tr) >> 1;
        long long from_l = 0;
        long long from_r = 0;
        if (bigs[x].left != -1) from_l = query(l, r, jl, jr, bigs[x].left, tl, m);
        if (bigs[x].right != -1) from_r = query(l, r, jl, jr, bigs[x].right, m+1, tr);
        return __gcd(from_l, from_r);
    }
};

const int SQ = 1e3+1;
segtree now;

void init(int R, int C) {
    create_big();
}
void update(int P, int Q, long long K) {
    now.update(P, Q, K);
}
long long calculate(int P, int Q, int U, int V) {
    return now.query(P, U, Q, V);
}

Compilation message

game.cpp:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
# Verdict Execution time Memory Grader output
1 Correct 39 ms 131668 KB Output is correct
2 Correct 42 ms 131556 KB Output is correct
3 Correct 45 ms 131716 KB Output is correct
4 Correct 38 ms 131516 KB Output is correct
5 Correct 40 ms 131668 KB Output is correct
6 Correct 41 ms 131664 KB Output is correct
7 Correct 41 ms 131668 KB Output is correct
8 Correct 42 ms 131628 KB Output is correct
9 Correct 62 ms 131616 KB Output is correct
10 Correct 59 ms 131536 KB Output is correct
11 Correct 44 ms 131528 KB Output is correct
12 Correct 39 ms 131676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 131668 KB Output is correct
2 Correct 39 ms 131668 KB Output is correct
3 Correct 44 ms 131664 KB Output is correct
4 Correct 515 ms 135584 KB Output is correct
5 Correct 425 ms 136016 KB Output is correct
6 Correct 504 ms 132800 KB Output is correct
7 Correct 520 ms 132520 KB Output is correct
8 Correct 377 ms 133208 KB Output is correct
9 Correct 551 ms 132436 KB Output is correct
10 Correct 482 ms 132272 KB Output is correct
11 Correct 42 ms 131664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 131660 KB Output is correct
2 Correct 45 ms 131512 KB Output is correct
3 Correct 39 ms 131736 KB Output is correct
4 Correct 50 ms 131708 KB Output is correct
5 Correct 44 ms 131776 KB Output is correct
6 Correct 52 ms 131668 KB Output is correct
7 Correct 39 ms 131700 KB Output is correct
8 Correct 44 ms 131664 KB Output is correct
9 Correct 42 ms 131664 KB Output is correct
10 Correct 40 ms 131676 KB Output is correct
11 Correct 63 ms 131608 KB Output is correct
12 Runtime error 2403 ms 256000 KB Execution killed with signal 9
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 75 ms 131520 KB Output is correct
2 Correct 66 ms 131664 KB Output is correct
3 Correct 47 ms 131664 KB Output is correct
4 Correct 69 ms 131664 KB Output is correct
5 Correct 63 ms 131752 KB Output is correct
6 Correct 66 ms 131664 KB Output is correct
7 Correct 39 ms 131580 KB Output is correct
8 Correct 42 ms 131604 KB Output is correct
9 Correct 44 ms 131668 KB Output is correct
10 Correct 65 ms 131668 KB Output is correct
11 Correct 44 ms 131668 KB Output is correct
12 Correct 539 ms 135740 KB Output is correct
13 Correct 432 ms 136124 KB Output is correct
14 Correct 580 ms 132628 KB Output is correct
15 Correct 530 ms 132432 KB Output is correct
16 Correct 407 ms 133200 KB Output is correct
17 Correct 517 ms 132468 KB Output is correct
18 Correct 525 ms 132212 KB Output is correct
19 Runtime error 2383 ms 256000 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 60 ms 131664 KB Output is correct
2 Correct 44 ms 131736 KB Output is correct
3 Correct 54 ms 131504 KB Output is correct
4 Correct 57 ms 131540 KB Output is correct
5 Correct 62 ms 131668 KB Output is correct
6 Correct 46 ms 131664 KB Output is correct
7 Correct 43 ms 131596 KB Output is correct
8 Correct 44 ms 131664 KB Output is correct
9 Correct 51 ms 131668 KB Output is correct
10 Correct 39 ms 131664 KB Output is correct
11 Correct 40 ms 131528 KB Output is correct
12 Correct 490 ms 135732 KB Output is correct
13 Correct 397 ms 136016 KB Output is correct
14 Correct 473 ms 132688 KB Output is correct
15 Correct 498 ms 132392 KB Output is correct
16 Correct 376 ms 133328 KB Output is correct
17 Correct 530 ms 132424 KB Output is correct
18 Correct 507 ms 132044 KB Output is correct
19 Runtime error 2332 ms 256000 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -