Submission #1193504

#TimeUsernameProblemLanguageResultExecution timeMemory
1193504InvMODRelativnost (COCI15_relativnost)C++17
0 / 140
141 ms131072 KiB
#include<bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define eb emplace_back

#define vi vector<int>
#define pi pair<int,int>
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define compact(v) (v).erase(unique(all(v)), (v).end())

template<class T> using upq = priority_queue<T, vector<T>, greater<T>>;
template<class T> int lwrbound(const vector<T>& a, const T& b, const int s = 0){return int(lower_bound(s + all(a), b) - a.begin());}
template<class T> int uprbound(const vector<T>& a, const T& b, const int s = 0){return int(upper_bound(s + all(a), b) - a.begin());}

#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define ROF(i, a, b) for(int i = (a); i >= (b); i--)
#define sumof(x) accumulate(all(x), 0ll)
#define dbg(x) "[" << #x " = " << (x) << "]"
#define el "\n"

using ll = long long;
using ld = long double;

template<class T> bool ckmx(T& a, const T b){return (a < b ? a = b, true : false);}
template<class T> bool ckmn(T& a, const T b){return (a > b ? a = b, true : false);}

const int N = 1e5 + 1, C = 21, MOD = 10007;


int n, q, c, a[N], b[N];

int mul(int x, int y){
    return (x * y) % MOD;
}

void add(int& x, int y){
    x += y;
    if(x >= MOD) x -= MOD;
}

namespace SMT{
    int st[N << 2][C];

    void merge_st(int id){
        for(int i = 0; i <= c; i++) st[id][i] = 0;

        for(int i = 0; i <= c; i++){
            for(int j = 0; j <= c; j++){
                add(st[id][min(i + j, c)], mul(st[id << 1][i], st[id << 1|1][j]));
            }
        }
    }

    void build(int id, int l, int r){
        if(l == r){
            st[id][0] = b[l] % MOD;
            st[id][1] = a[l] % MOD;
        }
        else{
            int m = l+r>>1;
            build(id << 1, l, m);
            build(id << 1|1, m+1, r);
            merge_st(id);
        }
    }

    void update(int id, int l, int r, int x){
        if(l == r){
            st[id][0] = b[x] % MOD;
            st[id][1] = a[x] % MOD;
        }
        else{
            int m = l+r>>1;
            if(x <= m)
                update(id << 1, l, r, x);
            else update(id << 1|1, m+1, r, x);
            merge_st(id);
        }
    }

    int ans(){
        return st[1][c];
    }
};


void Main()
{
    cin >> n >> c;
    FOR(i, 1, n) cin >> a[i];
    FOR(i, 1, n) cin >> b[i];

    SMT::build(1, 1, n);

    cin >> q;
    while(q--){
        int p; cin >> p >> a[p] >> b[p];

        SMT::update(1, 1, n, p);
        cout << SMT::ans() << el;
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    #define name "InvMOD"
    if(fopen(name".INP", "r")){
        freopen(name".INP", "r", stdin);
        freopen(name".OUT", "w", stdout);
    }

    int t = 1; while(t--) Main();
    return 0;
}

Compilation message (stderr)

relativnost.cpp: In function 'int32_t main()':
relativnost.cpp:116:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |         freopen(name".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
relativnost.cpp:117:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |         freopen(name".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...