#include <cstdio>
#include <map>
#include <utility>
#include <cassert>
#define let const auto
#define rep(name,beg,end) for(auto lim_##name = end,name = beg;name <= lim_##name;name++)
#define per(name,beg,end) for(auto lim_##name = end,name = beg;name >= lim_##name;name--)
#define repn(lim) for(auto REPN_LIM = lim,REPN = 1;REPN <= REPN_LIM;REPN++)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define trace() debug("Line : %d, Function : %s\n",__LINE__,__FUNCTION__)
using ll = long long;
constexpr int maxn = 1e5 + 10,maxm = 20,mod = 1e4 + 7;
constexpr int mul(const int a,const int b){return a * b % mod;}
int qpow(int base,int b){
int res = 1;
while(b){
if(b & 1)res = res * base % mod;
base = base * base % mod;
b >>= 1;
}
return res;
}
int n,c,a[maxn],b[maxn];
namespace seg{
#define ls (x << 1)
#define rs (x << 1 | 1)
unsigned short val[maxn << 2][maxm];
void pushup(const int x){
rep(i,0,c - 1){
int s = 0;
rep(j,0,i)s += int(val[ls][j]) * val[rs][i - j];
val[x][i] = s;
}
}
void build(const int l = 1,const int r = n,const int x = 1){
if(l ==r){
let a = ::a[l],b = ::b[l];
val[x][0] = b % mod;
val[x][1] = a % mod;
return;
}
let mid = (l + r) >> 1;
build(l,mid,ls);
build(mid + 1,r,rs);
pushup(x);
}
void modify(const int p,const int a,const int b,const int l = 1,const int r = n,const int x = 1){
if(l == r){
val[x][0] = b % mod;
val[x][1] = a % mod;
return;
}
let mid = (l + r) >> 1;
if(p <= mid)modify(p,a,b,l,mid,ls);
else modify(p,a,b,mid + 1,r,rs);
pushup(x);
}
#undef ls
#undef rs
}
int ans = 1;
int main(){
// std::freopen("relativnost.in","r",stdin);
// std::freopen("relativnost.out","w",stdout);
std::scanf("%d %d",&n,&c);
rep(i,1,n)
std::scanf("%d %d",a + i,b + i),
a[i] %= mod,
b[i] %= mod,
ans = ans * ((a[i] + b[i]) % mod) % mod;
seg::build();
int q; std::scanf("%d",&q);
repn(q){
int p,x,y; std::scanf("%d %d %d",&p,&x,&y);
seg::modify(p,x,y);
ans = ans * qpow((a[p] + b[p]) % mod,mod - 2) % mod;
x %= mod,y %= mod;
ans = ans * ((x + y) % mod) % mod;
a[p] = x; b[p] = y;
int out = ans;
rep(i,0,c - 1)
out -= seg::val[1][i];
out %= mod;
out += mod;
out %= mod;
std::printf("%d\n",out);
}
std::fclose(stdin);
std::fclose(stdout);
return 0;
}
Compilation message
relativnost.cpp: In function 'int main()':
relativnost.cpp:65:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | std::scanf("%d %d",&n,&c);
| ~~~~~~~~~~^~~~~~~~~~~~~~~
relativnost.cpp:67:13: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | std::scanf("%d %d",a + i,b + i),
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
relativnost.cpp:72:19: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | int q; std::scanf("%d",&q);
| ~~~~~~~~~~^~~~~~~~~
relativnost.cpp:74:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | int p,x,y; std::scanf("%d %d %d",&p,&x,&y);
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
336 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
328 KB |
Output isn't correct |
4 |
Incorrect |
85 ms |
8628 KB |
Output isn't correct |
5 |
Incorrect |
187 ms |
15008 KB |
Output isn't correct |
6 |
Incorrect |
204 ms |
14784 KB |
Output isn't correct |
7 |
Incorrect |
114 ms |
8776 KB |
Output isn't correct |
8 |
Incorrect |
95 ms |
14440 KB |
Output isn't correct |
9 |
Incorrect |
141 ms |
15048 KB |
Output isn't correct |
10 |
Incorrect |
317 ms |
14920 KB |
Output isn't correct |