답안 #590643

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
590643 2022-07-06T07:59:02 Z Loki_Nguyen Relativnost (COCI15_relativnost) C++14
56 / 140
177 ms 5864 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, int>
#define fi first
#define se second
#define pb push_back

const int N = 2e5 + 3;
const int M = 1 << 24;
const int mod = 1e4 + 7;
const int base = 300;
const ll inf = 1e12;
int pw(int k, int n)
{
    int total = 1;
    for (; n; n >>= 1)
    {
        if (n & 1)
            total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}
int m, n, t, k, a[N], ans, b[N], c[N], d[N];
int dp[N], tong;
vector<pll> adj[N];
vector<int> kq, val;

ll lwr(ll x)
{
    return lower_bound(kq.begin(), kq.end(), x) - kq.begin();
}

void sol()
{
    cin >> n >> k;
    dp[0] = 1;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
        cin >> b[i];
    tong = 1;
    for (int i = 1; i <= n; i++)
    {
        a[i] %= mod;
        b[i] %= mod;
        tong = (a[i] + b[i]) % mod * tong % mod;
        for (int j = k; j > 0; j--)
            dp[j] = (dp[j] * b[i] % mod + dp[j - 1] * a[i] % mod) % mod;
        dp[0] = dp[0] * b[i] % mod;
    }
    cin >> m;
    while (m-- > 0)
    {
        int i, x, y;
        cin >> i >> x >> y;
        dp[0] = dp[0] * pw(b[i], mod - 2) % mod;
        for (int j = 1; j <= k; j++)
        {
            dp[j] = (dp[j] + mod - dp[j - 1] * a[i] % mod) % mod;
            dp[j] = dp[j] * pw(b[i], mod - 2) % mod;
        }
        tong = tong * pw((a[i] + b[i]) % mod, mod - 2) % mod;
        a[i] = x % mod;
        b[i] = y % mod;
        for (int j = k; j > 0; j--)
            dp[j] = (dp[j] * b[i] % mod + dp[j - 1] * a[i] % mod) % mod;
        dp[0] = dp[0] * b[i] % mod;
        tong = (a[i] + b[i]) % mod * tong % mod;
        ans = tong;
        for (int j = 0; j < k; j++)
            ans = (ans + mod - dp[j]) % mod;
        cout << ans << '\n';
    }
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
#define task "tests"
    if (fopen(task ".in", "r"))
    {
        freopen(task ".in", "r", stdin);
        // freopen(task".out", "w", stdout);
    }
    int ntest = 1;
    // cin >> ntest;
    while (ntest-- > 0)
        sol();
}

Compilation message

relativnost.cpp: In function 'int main()':
relativnost.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         freopen(task ".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 5 ms 4948 KB Output is correct
4 Incorrect 90 ms 5552 KB Output isn't correct
5 Incorrect 129 ms 5864 KB Output isn't correct
6 Incorrect 130 ms 5836 KB Output isn't correct
7 Incorrect 95 ms 5628 KB Output isn't correct
8 Correct 76 ms 5856 KB Output is correct
9 Incorrect 124 ms 5708 KB Output isn't correct
10 Incorrect 177 ms 5680 KB Output isn't correct