# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
47718 | tieunhi | Relativnost (COCI15_relativnost) | C++14 | 1 ms | 528 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define N 100005
#define mid (r + l)/2
#define L id*2
#define R id*2+1
#define mod 10007
using namespace std;
int n, C, a[N], b[N];
struct IntervalTree
{
int t[N << 2][20];
int s[N << 2];
void build(int l, int r, int id)
{
if (l == r)
{
t[id][1] = a[l];
t[id][0] = b[l];
s[id] = a[l] + b[l];
return;
}
build(l, mid, L);
build(mid+1, r, R);
for (int i = 0; i < C; i++)
for (int j = 0; j < C; j++)
if (i + j < C)
t[id][i+j] = (t[id][i+j] + (t[L][i]*t[R][j]) % mod) % mod;
s[id] = (s[L]*s[R]) % mod;
}
void update(int l, int r, int id, int x)
{
if (l > x || r < x) return;
if (l == r)
{
t[id][1] = a[l];
t[id][0] = b[l];
s[id] = a[l] + b[l];
return;
}
if (x <= mid) update(l, mid, L, x);
else update(mid+1, r, R, x);
for (int i = 0; i < C; i++) t[id][i] = 0;
for (int i = 0; i < C; i++)
for (int j = 0; j < C; j++)
if (i + j < C)
t[id][i+j] = (t[id][i+j] + (t[L][i]*t[R][j]) % mod) % mod;
s[id] = (s[L]*s[R]) % mod;
}
int get()
{
int res = 0;
for (int i = 0; i < C; i++)
res = (res + t[1][i]);
return (s[1] - res + mod) % mod;
}
}t;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("INP.TXT", "r", stdin);
cin >> n >> C;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
t.build(1, n, 1);
int numQuery; cin >> numQuery;
while (numQuery--)
{
int pos, u, v; cin >> pos >> u >> v;
a[pos] = u; b[pos] = v;
t.update(1, n, 1, pos);
cout <<t.get()<<'\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |