#include<bits/stdc++.h>
using namespace std;
#define task "sol"
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define zs(v) ((int)(v).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define CNTBIT __builtin_popcountll
#define ALL(v) (v).begin(),(v).end()
#define endl '\n'
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
const int dx[4]={-1, 0, 1, 0}, dy[4]={0, 1, 0, -1};
const int dxx[8]={-1, -1, 0, 1, 1, 1, 0, -1}, dyy[8]={0, 1, 1, 1, 0, -1, -1, -1};
const ll mod = 10007; /// 998244353
const ll base = 331;
const int N=1e5+1;
int n,c,a[N],b[N];
short st[N<<2][21];
void join(int p, short dp[21], short f[21], short g[21])
{
for (int i=0;i<=c;++i) dp[i]=0;
for (int i=0;i<=c;++i) if (f[i])
for (int j=0;j<=c;++j) if (g[j])
{
int k=min(i+j,c);
dp[k]+=(int)f[i]*g[j]%mod*b[p]%mod;
k++;
k=min(k,c);
dp[k]+=(int)f[i]*g[j]%mod*a[p]%mod;
dp[k]%=mod;
}
}
void update(int i, int l, int r, int p)
{
if (l==r)
{
st[i][0]=1;
for (int j=1;j<=c;++j) st[i][j]=0;
return;
}
int mid=(l+r)/2;
if (p<=mid) update(i<<1,l,mid,p);
else update(i<<1|1,mid+1,r,p);
join(mid+1, st[i],st[i<<1],st[i<<1|1]);
// cout<<i<<" "<<l<<" "<<r<<" "<<st[i][0]<<" "<<st[i][1]<<" "<<st[i][2]<<endl;
}
void gogo()
{
cin>>n>>c;
for (int i=1;i<=n;++i) cin>>a[i], a[i]%=mod;
for (int i=1;i<=n;++i) cin>>b[i], b[i]%=mod;
for (int i=0;i<=n;++i) update(1,0,n,i);
int q;
cin>>q;
while (q--)
{
int i,x,y;
cin>>i>>x>>y;
a[i]=x, b[i]=y;
a[i]%=mod;
b[i]%=mod;
// cout<<a[i]<<" "<<b[i]<<endl;
update(1,0,n,i);
cout<<st[1][c]<<endl;
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
if (fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
gogo();
}
Compilation message
relativnost.cpp: In function 'int main()':
relativnost.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
84 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
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".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
460 KB |
Output is correct |
2 |
Correct |
15 ms |
332 KB |
Output is correct |
3 |
Correct |
27 ms |
440 KB |
Output is correct |
4 |
Correct |
571 ms |
9028 KB |
Output is correct |
5 |
Correct |
1878 ms |
16024 KB |
Output is correct |
6 |
Correct |
2965 ms |
15512 KB |
Output is correct |
7 |
Correct |
1224 ms |
9384 KB |
Output is correct |
8 |
Correct |
664 ms |
15040 KB |
Output is correct |
9 |
Correct |
1227 ms |
16124 KB |
Output is correct |
10 |
Execution timed out |
4066 ms |
15764 KB |
Time limit exceeded |