답안 #230575

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
230575 2020-05-10T13:12:44 Z ParsaAlizadeh Relativnost (COCI15_relativnost) C++17
126 / 140
4000 ms 27956 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")

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

typedef long long int   ll;
typedef pair<ll, ll>    pll;
typedef pair<int, int>  pii;

#define all(x)          x.begin(), x.end()
#define kill(x)         return cout << x << endl, 0
#define X               first
#define Y               second
#define sep             ' '
#define endl            '\n'

template<class T = ll>
T nxt() {T x; cin >> x; return x;}

ll pw(ll a, ll b, ll mod) {
    if (!b)    return 1;
    if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;
    return pw(a * a % mod, b / 2, mod) % mod;
}

const int N    = 1e5 + 10;
const int K    = 22;
const int MOD  = 10007;

int n, q, A[N], B[N], k, seg[N << 2][K];

void Merge(int id) {
    for (int i = 0; i <= k; i++) {
        seg[id][i] = 0;
    }
    for (int i = 0; i <= k; i++) {
        for (int j = 0; j <= k; j++) {
            seg[id][min(k, i + j)] += seg[2 * id][i] * seg[2 * id + 1][j] % MOD;
            seg[id][min(k, i + j)] %= MOD;
        }
    }
}

void Build(int id, int l, int r) {
    if (r - l == 1) {
        seg[id][0] = B[l];
        seg[id][1] = A[l];
        return;
    }
    int mid = (l + r) >> 1;
    Build(2 * id, l, mid);
    Build(2 * id + 1, mid, r);
    Merge(id);
}

void Update(int id, int l, int r, int ind) {
    if (ind < l || r <= ind)
        return;
    if (r - l == 1) {
        seg[id][0] = B[l];
        seg[id][1] = A[l];
        return;
    }
    int mid = (l + r) >> 1;
    if (ind < mid)
        Update(2 * id, l, mid, ind);
    else
        Update(2 * id + 1, mid, r, ind);
    Merge(id);
}

int main() {
    //ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) {
        scanf("%d", &(A[i])); A[i] %= MOD;
    }
    for (int i = 0; i < n; i++) {
        scanf("%d", &(B[i])); B[i] %= MOD;
    }
    Build(1, 0, n);
    scanf("%d", &q);
    while (q--) {
        int ind, a, b;
        cin >> ind >> a >> b; ind--;
        A[ind] = a % MOD;
        B[ind] = b % MOD;
        Update(1, 0, n, ind);
        printf("%d\n", seg[1][k]);
    }
    return 0;
}

Compilation message

relativnost.cpp: In function 'int main()':
relativnost.cpp:76:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~~
relativnost.cpp:78:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &(A[i])); A[i] %= MOD;
         ~~~~~^~~~~~~~~~~~~~~
relativnost.cpp:81:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &(B[i])); B[i] %= MOD;
         ~~~~~^~~~~~~~~~~~~~~
relativnost.cpp:84:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &q);
     ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 512 KB Output is correct
2 Correct 33 ms 512 KB Output is correct
3 Correct 34 ms 632 KB Output is correct
4 Correct 664 ms 15096 KB Output is correct
5 Correct 1822 ms 27956 KB Output is correct
6 Correct 2580 ms 27664 KB Output is correct
7 Correct 1236 ms 15476 KB Output is correct
8 Correct 724 ms 26872 KB Output is correct
9 Correct 1281 ms 27768 KB Output is correct
10 Execution timed out 4026 ms 27788 KB Time limit exceeded