# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
165232 | Atill83 | Relativnost (COCI15_relativnost) | C++14 | 4098 ms | 21496 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |