Submission #98731

# Submission time Handle Problem Language Result Execution time Memory
98731 2019-02-25T13:16:17 Z luckyboy Relativnost (COCI15_relativnost) C++14
140 / 140
1532 ms 24440 KB
/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 100005
#define maxm 500005
#define pii pair <int,int>
#define Task "RELATIVNOST"
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
using namespace std;
const int mod = 10007;
int n,c,q,a[maxn],b[maxn],t[maxn << 2][21],val[maxn << 2];
void Build(int l,int r,int id)
{
    if (l == r)
    {
        t[id][0] = b[l] % mod;
        t[id][1] = a[l] % mod;
        val[id] = (a[l] + b[l]) % mod;
        return;
    }
    int mid = (l+r) >> 1;
    Build(l,mid,2*id);
    Build(mid+1,r,2*id+1);
    FOR(i,0,c)
        FOR(j,0,i)
            {
                t[id][i] = (t[id][i] + t[2*id][j]*t[2*id+1][i-j]) % mod;
            }
    val[id] = (val[2*id] * val[2*id+1]) % mod;
}
void Update(int l,int r,int id,int x)
{
    if (l == r)
    {
        FOR(i,0,c) t[id][i] = 0;
        t[id][0] = b[l] % mod;
        t[id][1] = a[l] % mod;
        val[id] = (a[l] + b[l]) % mod;
        return;
    }
    int mid = (l+r) >> 1;
    if (mid >= x) Update(l,mid,2*id,x);
    else Update(mid+1,r,2*id+1,x);
    FOR(i,0,c)
        {
            t[id][i] = 0;
            FOR(j,0,i)
                t[id][i] = (t[id][i] + t[2*id][j]*t[2*id+1][i-j]) % mod;
        }
    val[id] = (val[2*id] * val[2*id+1]) % mod;
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen(Task".inp", "r",stdin);
    //freopen(Task".out", "w",stdout);
    cin >> n >> c;
    FOR(i,1,n) cin >> a[i];
    FOR(i,1,n) cin >> b[i];
    Build(1,n,1);
    cin >> q;
    while (q--)
    {
        int x,y,z;
        cin >> x >> y >> z;
        a[x] = y,
        b[x] = z;
        Update(1,n,1,x);
        int ans = val[1];
        FOR(i,0,c - 1)
        {
            ans -= t[1][i];
            if (ans < 0) ans += mod;
        }
        cout << ans << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 512 KB Output is correct
2 Correct 9 ms 512 KB Output is correct
3 Correct 14 ms 512 KB Output is correct
4 Correct 291 ms 12588 KB Output is correct
5 Correct 744 ms 24356 KB Output is correct
6 Correct 1035 ms 24440 KB Output is correct
7 Correct 560 ms 12664 KB Output is correct
8 Correct 396 ms 24040 KB Output is correct
9 Correct 539 ms 24440 KB Output is correct
10 Correct 1532 ms 24244 KB Output is correct