Submission #485879

#TimeUsernameProblemLanguageResultExecution timeMemory
485879leductoanRelativnost (COCI15_relativnost)C++11
126 / 140
4040 ms12568 KiB
#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 p) { int l=0, r=n, i=1; vector<pii> path; while (true) { if (l==r) { assert(l==p); for (int j=0;j<=c;++j) st[i][j]=0; st[i][0]=1; break; } int mid=(l+r)>>1; path.pb(mp(mid+1,i)); if (p<=mid) r=mid, i=i*2; else l=mid+1, i=i*2+1; } reverse(ALL(path)); for (pii i:path) join(i.fi,st[i.se],st[i.se<<1],st[i.se<<1|1]); } 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(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(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 (stderr)

relativnost.cpp: In function 'int main()':
relativnost.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
relativnost.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...