Submission #971955

# Submission time Handle Problem Language Result Execution time Memory
971955 2024-04-29T15:01:39 Z vjudge1 Relativnost (COCI15_relativnost) C++17
140 / 140
2649 ms 30136 KB
//hivongAC=)))
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 10007;
const int mx = 1e5 + 5;
int n, c, q;
int v;
int ap, bp;
int a[mx], b[mx];
struct Node{
    int chosen[21];
    Node(){
        memset(chosen, 0, sizeof(chosen));
    }
    Node operator + (const Node& lr){
        Node res;
        for (int i = 0; i <= c; i++) {
			for (int j = 0; j <= c; j++) {
				res.chosen[min(c, i + j)] = (res.chosen[min(c, i + j)] + chosen[i] * lr.chosen[j]) % maxn;
			}
		}
        return res;
    }
} st[3 * mx];
void build(int id, int l, int r){
    if(l == r){
        st[id].chosen[0] = b[l] % maxn;
        st[id].chosen[1] = a[r] % maxn;
        return;
    }
    int m = l + r >> 1;
    build(id * 2, l, m);
    build(id * 2 + 1, m + 1, r);
    st[id] = st[id * 2] + st[id * 2 + 1];
}
void update(int id, int l, int r, int v, int ap, int bp){
    if(v < l || r < v) return;
    if(l == r){
        a[v] = ap;
        st[id].chosen[1] = a[v] % maxn;
        b[v] = bp;
        st[id].chosen[0] = b[v] % maxn;
        return;
    }
    int m = l + r >> 1;
    update(id * 2, l, m, v, ap, bp);
    update(id * 2 + 1, m + 1, r, v, ap, bp);
    st[id] = st[id * 2] + st[id * 2 + 1];
}
int main(){
    cin >> n >> c;
    for(int i = 1 ; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++) cin >> b[i];
    build(1, 1, n);
    cin >> q;
    while(q--){
        cin >> v >> ap >> bp;
        update(1, 1, n, v, ap, bp);
        cout << st[1].chosen[c] << "\n";
    }
}

Compilation message

relativnost.cpp: In function 'void build(int, int, int)':
relativnost.cpp:32:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 |     int m = l + r >> 1;
      |             ~~^~~
relativnost.cpp: In function 'void update(int, int, int, int, int, int)':
relativnost.cpp:46:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |     int m = l + r >> 1;
      |             ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 25180 KB Output is correct
2 Correct 19 ms 25180 KB Output is correct
3 Correct 28 ms 25176 KB Output is correct
4 Correct 458 ms 28596 KB Output is correct
5 Correct 1201 ms 29840 KB Output is correct
6 Correct 1718 ms 29544 KB Output is correct
7 Correct 839 ms 28672 KB Output is correct
8 Correct 480 ms 29264 KB Output is correct
9 Correct 824 ms 30136 KB Output is correct
10 Correct 2649 ms 29700 KB Output is correct