Submission #31663

#TimeUsernameProblemLanguageResultExecution timeMemory
31663long10024070Relativnost (COCI15_relativnost)C++11
0 / 140
0 ms1840 KiB
#include <iostream> #include <cstdio> using namespace std; const string TASK = "Relativnost"; const short Mod = 1e4 + 7; const int maxn = 1e5 + 1; struct T_node { int l,r; short f[21]; }; int n,id[maxn]; short c,a[maxn],b[maxn]; T_node node[maxn*20]; void Enter() { cin >> n >> c; int x; for (int i=1;i<=n;++i) { cin >> x; a[i] = x % Mod; } for (int i=1;i<=n;++i) { cin >> x; b[i] = x % Mod; } } void Build_tree(int i, int l, int r) { node[i].l = l; node[i].r = r; if (l == r) id[l] = i; else { Build_tree(i*2,l,(l+r)/2); Build_tree(i*2+1,(l+r)/2+1,r); } } void Update(const int &i) { fill(node[i].f,node[i].f+c+1,0); node[i].f[1] = a[node[i].l]; node[i].f[0] = b[node[i].l]; int t = i / 2; while (t != 0) { fill(node[t].f,node[t].f+c+1,0); for (short j=0;j<=c;++j) for (short k=0;k<=c;++k) { short l = (j + k); node[t].f[min(c,l)] = (node[t].f[min(c,l)] + node[t*2].f[j] * node[t*2+1].f[k] % Mod) % Mod; } t /= 2; } } void Init() { Build_tree(1,1,n); for (int i=1;i<=n;++i) Update(id[i]); } void Solve() { int q,p,A,B; for (cin>>q;q>0;--q) { cin >> p >> A >> B; a[p] = A % Mod; b[p] = B % Mod; Update(id[p]); cout << node[1].f[c] << '\n'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen((TASK+".INP").c_str(),"r",stdin); //freopen((TASK+".OUT").c_str(),"w",stdout); Enter(); Init(); Solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...