제출 #1335487

#제출 시각아이디문제언어결과실행 시간메모리
1335487doantaolaaidiRelativnost (COCI15_relativnost)C++20
56 / 140
139 ms2044 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define AC "test"
#define foru(i, l, r) for (int i = (l); i <= (r); i++)
#define ford(i, l, r) for (int i = (l); i >= (r); i--)
#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vii;
typedef vector<ll> vll;

const ll inf = 1e9 + 7;
const ll linf = 1e18 + 7;
const int mod = 1e4 + 7;
const int maxn = 1e6 + 7;
const int base = 31;

void fastIO(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

ll mul(ll a, ll b){
    return (a * b) % mod;
}

ll Pow(ll a, ll b){
    ll ans = 1;
    while (b){
        if (b % 2) ans = mul(ans, a);
        a = mul(a, a);
        b/=2;
    }
    return ans;
}

ll n, c, a[maxn], b[maxn], way[maxn], cntall, res, lx, ly, sum, clsf, x, y, q;

void solve(){
    cin >> n >> c;
    way[0] = 1;
    foru(i, 1, n){
        cin >> a[i];
    }
    foru(i, 1, n){
        cin >> b[i];
    }
    cntall = 1;
    foru(i, 1, n){
        cntall = mul(cntall, (a[i] + b[i]));
        ford(j, c - 1, 1){
            way[j] = mul(way[j], b[i]);
            way[j] += mul(way[j - 1], a[i]);
            while (way[j] > mod) way[j] -= mod;
        }
        way[0] = mul(way[0], b[i]);
    }
    cin >> q;
    while(q--){
        cin >> clsf >> x >> y;
        lx = a[clsf];
        ly = b[clsf];
        cntall = mul(mul(cntall, x + y), Pow(lx + ly, mod - 2));
        way[0] = mul(way[0], Pow(ly, mod - 2));
        foru(i, 1, c - 1){
            way[i] -= mul(lx, way[i - 1]);
            while (way[i] < 0) way[i] += mod;
            way[i] = mul(way[i], Pow(ly, mod - 2));
        }
        a[clsf] = x;
        b[clsf] = y;
        ford(j, c - 1, 1){
            way[j] = mul(way[j], b[clsf]);
            way[j] += mul(way[j - 1], a[clsf]);
            while (way[j] > mod) way[j] -= mod;
        }
        way[0] = mul(way[0], b[clsf]);
        sum = 0;
        foru(i, 0, c - 1){
            sum = (sum + way[i]) % mod;
        }
        res = cntall - sum;
        while (res < 0) res += mod;
        cout << res << "\n";
    }
}

int main(){
    fastIO();
    if (fopen(AC".inp", "r")){
        freopen(AC".inp", "r", stdin);
        freopen(AC".out", "w", stdout);
    }
    solve();
}

컴파일 시 표준 에러 (stderr) 메시지

relativnost.cpp: In function 'int main()':
relativnost.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |         freopen(AC".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
relativnost.cpp:96:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |         freopen(AC".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...