Submission #1370009

#TimeUsernameProblemLanguageResultExecution timeMemory
1370009eyadoozRelativnost (COCI15_relativnost)C++20
42 / 140
4094 ms22708 KiB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#define endl '\n'
#define mod 10007
// #define int long long

const int N=(1ll<<17);
vector<int> tree[2*N];
vector<int> merg(vector<int>* a, vector<int>* b) {
    if(a->empty()) a->resize(22, 0), (*a)[0]=1;
    if(b->empty()) b->resize(22, 0), (*b)[0]=1;
    vector<int> ans;
    ans.resize(22, 0);
    // ans[0]=1;
    for(int i = 0;i <= 21;i++) {
        for(int j=0;j<= 21;j++) {
            (*a)[i]%=mod;
            (*b)[i]%=mod;
            ans[min(21, i+j)]+=((*a)[i]*(*b)[j])%mod;
            ans[min(21, i+j)]%=mod;
        }
    }
    return ans;
}
void update(int x, int y, int j) {
    x+=N;
    tree[x].resize(22, 0);
    tree[x][0]=j, tree[x][1]=y;
    while(x>1) {
        x/=2;
        tree[x]=merg(&tree[2*x], &tree[2*x+1]);
    }
}
main()
{
    cin.tie(0) -> sync_with_stdio(0);

    int n, c;
    cin >> n >> c;
    int a[n+1]={}, b[n+1]={};
    for(int i=1;i <= n;i++) cin >> a[i];
    for(int i=1;i <= n;i++) cin >> b[i];
    for(int i = 1;i <= n;i++) update(i, a[i]%mod, b[i]%mod);
    int q;
    cin >> q;
    while(q--) {
        int p;
        cin >> p;
        int x, y;
        cin >> x >> y;
        a[p]=x, b[p]=y;
        a[p]%=mod, b[p]%=mod;
        update(p, x, y);
        vector<int> s=tree[1];
        int ans=0;
        for(int i=c;i<=21;i++) ans+=s[i]%mod, ans%=mod;
        cout << ans << endl;
    }
}

Compilation message (stderr)

relativnost.cpp:42:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   42 | main()
      | ^~~~
#Result Execution timeMemoryGrader output
Fetching results...