답안 #93651

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
93651 2019-01-10T14:25:54 Z ajmasin Relativnost (COCI15_relativnost) C++14
84 / 140
4000 ms 27156 KB
#include <bits/stdc++.h>
using namespace std;

#define REP(i, a, b) for(int i = a; i < b; i++)

const int maxn = 100100;
const int maxc = 25;
const int offset = (1<<17);
const int mod = 10007;

int n, c, q;

int niza[maxn];
int nizb[maxn];

int add(int a, int b)
{
    a += b;
    if(a >= mod) a -= mod;
    if(a < 0) a += mod;
    return a;
}

int mult(int a, int b)
{
    return a * b % mod;
}

struct tournament
{
    int brn[2 * offset][maxc];
    void update(int cvor)
    {
        REP(i, 0, c + 1) brn[cvor][i] = 0;
        REP(i, 0, c + 1)
        {
            REP(j, 0, c + 1)
            {
                int suma = i + j;
                if(suma > c) suma = c;
                brn[cvor][suma] = add(brn[cvor][suma], mult(brn[cvor * 2][i], brn[cvor * 2 + 1][j]));
            }
        }
        return;
    }
}T;

bool ok(char znak)
{
    if (znak >= '0' && znak <= '9') return 1;
    return 0;
}

int dajbroj()
{
    int ret = 0;
    char in;
    while(!ok(in = getchar_unlocked()));
    ret += in - '0';
    while(ok(in = getchar_unlocked()))
    {
        ret *= 10;
        ret += in - '0';
    }
    return ret;
}

int main()
{
    for(int i = 2 * offset - 1; i >= offset; i--) T.brn[i][0] = 1;
    n = dajbroj();
    c = dajbroj();
    int a, b;
    REP(i, 0, n)
    {
        //scanf("%d", &niza[i]);
        niza[i] = dajbroj();
        niza[i] %= mod;
    }
    REP(i, 0, n)
    {
        //scanf("%d", &nizb[i]);
        nizb[i] = dajbroj();
        nizb[i] %= mod;
    }
    REP(i, 0, n)
    {
        T.brn[i + offset][0] = nizb[i];
        T.brn[i + offset][1] = niza[i];
    }
    for(int i = offset - 1; i > 0; i--) T.update(i);
    q = dajbroj();
    int p;
    REP(i, 0, q)
    {
        //scanf("%d%d%d", &p, &a, &b);
        p = dajbroj();
        a = dajbroj();
        b = dajbroj();
        while(a >= mod) a -= mod;
        while(b >= mod) b -= mod;
        p--;
        T.brn[p + offset][0] = b;
        T.brn[p + offset][1] = a;
        p += offset;
        p /= 2;
        while(p)
        {
            T.update(p);
            p /= 2;
        }
        printf("%d\n", T.brn[1][c]);
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 25976 KB Output is correct
2 Correct 114 ms 25976 KB Output is correct
3 Correct 250 ms 26124 KB Output is correct
4 Correct 3191 ms 26816 KB Output is correct
5 Execution timed out 4033 ms 27024 KB Time limit exceeded
6 Execution timed out 4038 ms 27060 KB Time limit exceeded
7 Correct 3861 ms 27080 KB Output is correct
8 Correct 2793 ms 27156 KB Output is correct
9 Execution timed out 4022 ms 27056 KB Time limit exceeded
10 Execution timed out 4019 ms 26980 KB Time limit exceeded