Submission #93632

# Submission time Handle Problem Language Result Execution time Memory
93632 2019-01-10T12:36:04 Z dfistric Relativnost (COCI15_relativnost) C++14
140 / 140
3636 ms 23508 KB
#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 REP(i, n) FOR(i, 0, n)
#define ll long long

using namespace std;

const int OFF = (1 << 17);
const int MOD = 10007;
int tour[2 * OFF][22];
int A[OFF], B[OFF];
int C;

int add(int a, int b) {
  return (a + b) % MOD;
}

int mul(int a, int b) {
  return (a * b) % MOD;
}

void update(int x, int a, int b) {
  x += OFF;
  tour[x][0] = b % MOD;
  tour[x][1] = a % MOD;
  x /= 2;

  while (x) {
    REP(i, C + 1) tour[x][i] = 0;

    REP(i, C + 1) {
      REP(j, C + 1) {
        int t = min(C, i + j);
        tour[x][t] = add(tour[x][t], mul(tour[x * 2][i], tour[x * 2 + 1][j]));
      }
    }
    x /= 2;
  }

  return;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n, a, b, x;
  cin >> n >> C;

  REP(i, OFF) tour[i + OFF][0] = 1;
  REP(i, n) {
    cin >> a;
    tour[i + OFF][1] = a % MOD;
  }
  REP(i, n) {
    cin >> a;
    tour[i + OFF][0] = a % MOD;
  }
  
  FORd(x, OFF - 1, 1) {
    REP(i, C + 1) {
      REP(j, C + 1) {
        int t = min(C, i + j);
        tour[x][t] = add(tour[x][t], mul(tour[x * 2][i], tour[x * 2 + 1][j]));
      }
    } 
  }

  int q;
  cin >> q;
  REP(i, q) {
    cin >> x >> a >> b;
    update(x - 1, a, b);
    cout << tour[1][C] << "\n";
  }

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 90 ms 22904 KB Output is correct
2 Correct 126 ms 22904 KB Output is correct
3 Correct 296 ms 22980 KB Output is correct
4 Correct 460 ms 23160 KB Output is correct
5 Correct 1468 ms 23496 KB Output is correct
6 Correct 2216 ms 23388 KB Output is correct
7 Correct 1018 ms 23384 KB Output is correct
8 Correct 497 ms 23168 KB Output is correct
9 Correct 929 ms 23508 KB Output is correct
10 Correct 3636 ms 23492 KB Output is correct