답안 #57528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
57528 2018-07-15T08:13:45 Z Crown 게임 (IOI13_game) C++14
63 / 100
4756 ms 257024 KB
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;

const int maxr = 1e9+5;
const int maxc = 1e9+5; 

long long gcd2(long long X, long long Y)
{
    if(X == 0 || Y == 0)
    {
        return X+Y;
    }
    long long tmp;
    while(X != Y && Y != 0)
    {
        tmp = X;
        X = Y;
        Y = tmp%Y;
    }
    return X;
}

struct layer2_node
{
    layer2_node(int low, int high) : low(low), high(high), left(NULL), right(NULL), value(0LL) {}
    int low, high;
    layer2_node *left;
    layer2_node *right;
    ll value;   
};

struct layer1_node
{
    layer1_node() : left(NULL), right(NULL), l2(0, maxc) {} 
    layer1_node *left, *right;
    layer2_node l2;
};

static layer1_node root;

static void update2(layer2_node* node, int Q, long long K)
{
    int low = node->low;
    int high = node->high;
    int mid = (low+high)/2;
    if(low == high)
    {
        node->value = K;
        return;
    }

    layer2_node*& tgt = Q<=mid ? node->left : node->right;

    if(tgt == NULL)
    {
        tgt = new layer2_node(Q, Q);
        tgt->value = K;
    }
    else if(tgt->low <= Q && Q<= tgt->high)
    {
        update2(tgt, Q, K);
    }
    else
    {
        do
        {
            if(Q<= mid) high = mid;
            else low = mid+1;
            mid = (low+high)/2;
        }
        while((Q<= mid) == (tgt->low <= mid));

        layer2_node* newnode = new layer2_node(low, high);
        (tgt->low<= mid? newnode->left : newnode->right) = tgt;
        tgt = newnode;

        update2(newnode, Q, K);
    }
    node->value = gcd2(node->left? node->left->value: 0, node->right?node->right->value:0);
}

ll query2(layer2_node *nd, int A, int B)
{
    if(nd == NULL || B< nd->low || A> nd->high) return 0;
    else if(A<= nd->low && nd->high <= B) return nd->value;
    return gcd2(query2(nd->left, A, B), query2(nd->right, A, B));
}

static void update1(layer1_node *node, int low, int high, int P, int Q, ll K)
{
    int mid = (low+high)/2;
    if(low == high)
    {
        update2(&node->l2, Q, K);
    }
    else
    {
        layer1_node*& newnode = P<= mid? node->left : node->right;
        if(P<= mid) high = mid;
        else low = mid+1;
        if(newnode == NULL)
        {
            newnode = new layer1_node();
        }
        update1(newnode, low, high, P, Q, K);
        K = gcd2(node->left?query2(&node->left->l2, Q, Q) : 0, node->right?query2(&node->right->l2, Q, Q) : 0);
        update2(&node->l2, Q, K);
    }
}

ll query1(layer1_node* nd, int low, int high, int A1, int B1, int A2, int B2)
{
    if(nd == NULL || B1< low || high < A1)
    {
        return 0;
    }
    else if(A1<= low && high<= B1)
    {
        return query2(&nd->l2, A2, B2);
    }
    int mid = (low+high)/2;
    return gcd2(query1(nd->left, low, mid, A1, B1, A2, B2), query1(nd->right, mid+1, high, A1, B1, A2, B2));    
}
void init(int R, int C){}
void update(int P, int Q, long long K)
{
    update1(&root, 0, maxr, P, Q, K);
}

long long calculate(int P, int Q, int U, int V)
{
    return query1(&root, 0, maxr, P, U, Q, V);
}

Compilation message

grader.c: In function 'int main()':
grader.c:18:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
  int res;
      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 6 ms 748 KB Output is correct
3 Correct 4 ms 860 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 4 ms 860 KB Output is correct
6 Correct 5 ms 860 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 4 ms 864 KB Output is correct
10 Correct 4 ms 864 KB Output is correct
11 Correct 4 ms 892 KB Output is correct
12 Correct 3 ms 892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 892 KB Output is correct
2 Correct 3 ms 892 KB Output is correct
3 Correct 3 ms 892 KB Output is correct
4 Correct 1117 ms 37052 KB Output is correct
5 Correct 784 ms 41188 KB Output is correct
6 Correct 1739 ms 42916 KB Output is correct
7 Correct 1566 ms 47328 KB Output is correct
8 Correct 939 ms 47328 KB Output is correct
9 Correct 1701 ms 56160 KB Output is correct
10 Correct 1247 ms 60628 KB Output is correct
11 Correct 3 ms 60628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 60628 KB Output is correct
2 Correct 5 ms 60628 KB Output is correct
3 Correct 4 ms 60628 KB Output is correct
4 Correct 2 ms 60628 KB Output is correct
5 Correct 2 ms 60628 KB Output is correct
6 Correct 4 ms 60628 KB Output is correct
7 Correct 3 ms 60628 KB Output is correct
8 Correct 2 ms 60628 KB Output is correct
9 Correct 5 ms 60628 KB Output is correct
10 Correct 4 ms 60628 KB Output is correct
11 Correct 3 ms 60628 KB Output is correct
12 Correct 1292 ms 60628 KB Output is correct
13 Correct 2712 ms 60628 KB Output is correct
14 Correct 535 ms 60628 KB Output is correct
15 Correct 2996 ms 60628 KB Output is correct
16 Correct 692 ms 67004 KB Output is correct
17 Correct 1961 ms 67732 KB Output is correct
18 Correct 3643 ms 77472 KB Output is correct
19 Correct 3274 ms 82856 KB Output is correct
20 Correct 2525 ms 87628 KB Output is correct
21 Correct 3 ms 87628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 87628 KB Output is correct
2 Correct 6 ms 87628 KB Output is correct
3 Correct 6 ms 87628 KB Output is correct
4 Correct 3 ms 87628 KB Output is correct
5 Correct 2 ms 87628 KB Output is correct
6 Correct 5 ms 87628 KB Output is correct
7 Correct 3 ms 87628 KB Output is correct
8 Correct 4 ms 87628 KB Output is correct
9 Correct 5 ms 87628 KB Output is correct
10 Correct 4 ms 87628 KB Output is correct
11 Correct 3 ms 87628 KB Output is correct
12 Correct 1172 ms 110448 KB Output is correct
13 Correct 697 ms 114684 KB Output is correct
14 Correct 1473 ms 116452 KB Output is correct
15 Correct 1613 ms 120948 KB Output is correct
16 Correct 1059 ms 120948 KB Output is correct
17 Correct 1716 ms 129712 KB Output is correct
18 Correct 1375 ms 134228 KB Output is correct
19 Correct 1457 ms 134228 KB Output is correct
20 Correct 2655 ms 134228 KB Output is correct
21 Correct 502 ms 134228 KB Output is correct
22 Correct 3158 ms 134228 KB Output is correct
23 Correct 702 ms 140368 KB Output is correct
24 Correct 1862 ms 141100 KB Output is correct
25 Correct 3226 ms 151036 KB Output is correct
26 Correct 2901 ms 156324 KB Output is correct
27 Correct 2786 ms 161060 KB Output is correct
28 Correct 786 ms 190756 KB Output is correct
29 Correct 2013 ms 203492 KB Output is correct
30 Correct 4552 ms 203492 KB Output is correct
31 Correct 4756 ms 203840 KB Output is correct
32 Correct 600 ms 203840 KB Output is correct
33 Correct 835 ms 203840 KB Output is correct
34 Correct 1380 ms 239732 KB Output is correct
35 Correct 1961 ms 239732 KB Output is correct
36 Runtime error 3804 ms 257024 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 257024 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -