diff --git a/codeforces/1017/f.out b/codeforces/1017/f.out index becc549..3a33510 100644 --- a/codeforces/1017/f.out +++ b/codeforces/1017/f.out @@ -13,4 +13,4 @@ 2 3 1 2 3 1 1 2 3 1 2 3 -[code]: 0 \ No newline at end of file +[code]: 0 diff --git a/codeforces/1017/g.out b/codeforces/1017/g.out index 48ace40..2cbab80 100644 --- a/codeforces/1017/g.out +++ b/codeforces/1017/g.out @@ -12,4 +12,4 @@ 102 88 -[code]: 0 \ No newline at end of file +[code]: 0 diff --git a/codeforces/1017/h.cc b/codeforces/1017/h.cc index 810b3af..3a8c6e1 100644 --- a/codeforces/1017/h.cc +++ b/codeforces/1017/h.cc @@ -16,18 +16,62 @@ using f128 = long double; // }}} void solve() { - i32 n, q; + i64 n, q; cin >> n >> q; - vector a(n); - for (auto& e : a) cin >> e; - i32 k, l, r; + vector a(n); + map> m; + for (i64 i = 0; i < n; ++i) { + cin >> a[i]; + m[a[i]].emplace_back(i); + } + i64 k; + i64 l, r; while (q--) { cin >> k >> l >> r; - // perceived as a[i] / k (WRONG) - // + // NOTE: messed up one-indexing + --l; + --r; + set indices; + for (i64 i = 1; i <= floor(sqrt(k)); ++i) { + if (k % i) { + continue; + } + if (i != 1 && m.contains(i)) { + auto it = lower_bound(m[i].begin(), m[i].end(), l); + // NOTE: *it >= l unneedeed based on biesct + if (it != m[i].end() && *it <= r) + indices.emplace(*it); + } + if (k / i != i && m.contains(k / i)) { + auto it = lower_bound(m[k / i].begin(), m[k / i].end(), l); + if (it != m[k / i].end() && *it <= r) + // typo, did i (NOT what you wanted ot code) + indices.emplace(*it); + } + } + i64 ans = 0; + i64 i = l; + for (auto it = indices.begin(); it != indices.end(); ++it) { + // NOTE: confusion with maintaining invariants; decide one approach and go + ans += k * (*it - i); + while (k % a[*it] == 0) { + k /= a[*it]; + } + i = *it; + } + // NOTE: had to do l <= r + // NOTE: was just counting wrong, this way was better + if (i <= r) + ans += k * (r - i + 1); + cout << ans << '\n'; } } +// NOTE: didn't know data structure inserted value +// NOTE: was debugging and thought, for example, that u32 was the issue +// im not even inspectingmy thought s- i know this is impossible - why did i +// think this then? + int main() { // {{{ cin.tie(nullptr)->sync_with_stdio(false); cin.exceptions(cin.failbit); diff --git a/codeforces/1017/h.out b/codeforces/1017/h.out index e69de29..82e357a 100644 --- a/codeforces/1017/h.out +++ b/codeforces/1017/h.out @@ -0,0 +1,8 @@ +5 +6 +1629 +13 +12 +520 + +[code]: 0 \ No newline at end of file