# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
165232 | Atill83 | Relativnost (COCI15_relativnost) | C++14 | 4098 ms | 21496 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e4+7;
const int MAXN = (int) 3e5+5;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n, c, q;
ll a[MAXN], b[MAXN];
ll dp[MAXN][25];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
#ifdef Local
freopen("../IO/int.txt","r",stdin);
freopen("../IO/out.txt","w",stdout);
#endif
cin>>n>>c;
for(int i = 1; i <= n; i++){
cin>>a[i];
}
ll cur = 1;
for(int i = 1; i <= n; i++){
cin>>b[i];
cur *= (a[i] + 1)*(b[i] + 1) - 1;
cur %= mod;
}
/*for(int i = 1; i <= n; i++){
for(int j = 1; j < c; j++){
dp[i][j] = dp[i - 1][j - 1]*(b[i] + 1)%mod*a[i]% mod;
dp[i][j] += dp[i - 1][j]*(b[i])%mod;
dp[i][j] %= mod;
}
}*/
cin>>q;
while(q--){
int kis, an, bn;
cin>>kis>>an>>bn;
a[kis] = an;
b[kis] = bn;
ll cur = 1;
dp[0][0] = 1;
for(int i = 1; i <= n; i++){
cur *= a[i] + b[i];
cur %= mod;
}
for(int i = 1; i <= n; i++){
dp[i][0] = dp[i - 1][0]*b[i]%mod;
dp[i][0] %= mod;
//cout<<i<<endl;
//cout<<dp[i][0]<<" ";
for(int j = 1; j < c; j++){
dp[i][j] = dp[i - 1][j - 1]*a[i]% mod;
dp[i][j] += dp[i - 1][j]*b[i]%mod;
dp[i][j] %= mod;
// cout<<dp[i][j]<<" ";
}
//cout<<endl;
}
ll cik = 0;
for(int j = 0; j < c; j++){
cik += dp[n][j];
cik %= mod;
}
cout<<(cur - cik + mod)%mod<<endl;
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |