답안 #644975

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
644975 2022-09-25T17:20:32 Z BackNoob Relativnost (COCI15_relativnost) C++14
140 / 140
3036 ms 23124 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define MASK(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define BIT(x , i) ((x >> (i)) & 1)
#define TASK "task"
#define sz(s) (int) (s).size()
 
using namespace std;
const int mxN = 1e5 + 227;
const int inf = 1e9 + 277;
const int mod = 10007;
const ll infll = 1e18 + 7;
const int base = 307;
const int LOG = 20;
 
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
    if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
    if (a < b) {a = b; return true;} return false;
}
 
int n;
int k;
int q;
pair<int, int> a[mxN];

void add(int &a, int b)
{
    a += b;
    if(a >= mod)
        a -= mod;
}

struct IT{
    struct Node{
        int f[21];
        Node() {
            for(int i = 0; i < 21; i++) f[i] = 0;
        }
    };
    int n;
    vector<Node> t;
    IT(){}
    IT(int _n) {
        n = _n;
        int offset;
        for(offset = 1; offset < n; offset *= 2);
        t.resize(offset * 2);
    }

    Node BASE;

    void merge_node(Node &res, Node &a, Node &b)
    {
        for(int i = 0; i <= k; i++) res.f[i] = 0;
        for(int i = 0; i <= k; i++) {
            for(int j = 0; j <= k; j++) {
                add(res.f[min(k, i + j)], 1LL * a.f[i] * b.f[j] % mod);
            }   
        }
    }

    void build(int v, int tl, int tr)
    {
        if(tl == tr) {
            t[v].f[1] = a[tl].fi;
            t[v].f[0] = a[tl].se;
        }
        else {
            int tm = (tl + tr) / 2;
            build(v * 2, tl, tm);
            build(v * 2 + 1, tm + 1, tr);
            merge_node(t[v], t[v * 2], t[v * 2 + 1]);
        }
    }
    
    void update(int v, int tl, int tr, int pos, pair<int, int> val)
    {
        if(tl == tr) {
            t[v].f[1] = val.fi;
            t[v].f[0] = val.se;
        }
        else {
            int tm = (tl + tr) / 2;
            if(pos <= tm) update(v * 2, tl, tm, pos, val);
            else update(v * 2 + 1, tm + 1, tr, pos, val);
            merge_node(t[v], t[v * 2], t[v * 2 + 1]);
        }
    }

    void update(int pos, pair<int, int> val)
    {
        update(1, 1, n, pos, val);
    }
} seg;


void solve()
{
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i].fi;
    for(int i = 1; i <= n; i++) cin >> a[i].se;

    seg = IT(n);
    seg.build(1, 1, n);

    cin >> q;
    while(q--) {
        int idx, x, y;
        cin >> idx >> x >> y;
        a[idx] = {x, y};
        seg.update(idx, a[idx]);
        cout << seg.t[1].f[k] << endl;
    }
}
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

 
    int tc = 1;
    //cin >> tc;
    while(tc--) {
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 468 KB Output is correct
2 Correct 11 ms 468 KB Output is correct
3 Correct 22 ms 596 KB Output is correct
4 Correct 394 ms 11860 KB Output is correct
5 Correct 1286 ms 23124 KB Output is correct
6 Correct 1934 ms 22976 KB Output is correct
7 Correct 817 ms 11848 KB Output is correct
8 Correct 432 ms 22904 KB Output is correct
9 Correct 789 ms 22952 KB Output is correct
10 Correct 3036 ms 22840 KB Output is correct