Submission #624233

# Submission time Handle Problem Language Result Execution time Memory
624233 2022-08-07T13:48:29 Z MilosMilutinovic Relativnost (COCI15_relativnost) C++14
28 / 140
4000 ms 22888 KB
/**
 *    author:  wxhtzdy
 *    created: 07.08.2022 15:06:04
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n, c;
  cin >> n >> c;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].first %= 10007;
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i].second;
    a[i].second %= 10007;
  }
  vector<vector<int>> dp(2 * n + 1, vector<int>(c + 1));
  function<void(int)> Update = [&](int i) {
    i += n;             
    for (int j = 0; j <= c; j++) {
      dp[i][j] = 0;
    }
    dp[i][0] = a[i - n].second;
    dp[i][1] = a[i - n].first;
    for (i /= 2; i > 0; i /= 2) {
      for (int p = 0; p <= c; p++) {
        dp[i][p] = 0;
      }
      for (int p = 0; p <= c; p++) {
        for (int q = 0; q <= c; q++) {
          dp[i][min(p + q, c)] += dp[i * 2][p] * dp[i * 2 + 1][q];
        }
      }
      for (int p = 0; p <= c; p++) {
        dp[i][p] %= 10007;
      }
    }
  };                     
  for (int i = 0; i < n; i++) {
    Update(i); 
  }
  int q;
  cin >> q;
  while (q--) {
    int idx, x, y;
    cin >> idx >> x >> y;
    --idx;
    x %= 10007;
    y %= 10007; 
    a[idx].first = x;
    a[idx].second = y;
    Update(idx);
    cout << dp[1][c] << '\n';
  }                                                        
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 340 KB Output isn't correct
2 Incorrect 15 ms 468 KB Output isn't correct
3 Incorrect 31 ms 476 KB Output isn't correct
4 Correct 556 ms 8376 KB Output is correct
5 Incorrect 2050 ms 16204 KB Output isn't correct
6 Incorrect 3638 ms 22888 KB Output isn't correct
7 Incorrect 1437 ms 11980 KB Output isn't correct
8 Correct 863 ms 13924 KB Output is correct
9 Incorrect 1141 ms 11880 KB Output isn't correct
10 Execution timed out 4067 ms 17844 KB Time limit exceeded