feat(codeforces/1017): f & g
This commit is contained in:
parent
a01abe65ee
commit
b2c025f345
4 changed files with 60 additions and 8 deletions
|
|
@ -16,18 +16,62 @@ using f128 = long double;
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
void solve() {
|
void solve() {
|
||||||
i32 n, q;
|
i64 n, q;
|
||||||
cin >> n >> q;
|
cin >> n >> q;
|
||||||
vector<i32> a(n);
|
vector<i64> a(n);
|
||||||
for (auto& e : a) cin >> e;
|
map<i32, vector<u32>> m;
|
||||||
i32 k, l, r;
|
for (i64 i = 0; i < n; ++i) {
|
||||||
|
cin >> a[i];
|
||||||
|
m[a[i]].emplace_back(i);
|
||||||
|
}
|
||||||
|
i64 k;
|
||||||
|
i64 l, r;
|
||||||
while (q--) {
|
while (q--) {
|
||||||
cin >> k >> l >> r;
|
cin >> k >> l >> r;
|
||||||
// perceived as a[i] / k (WRONG)
|
// NOTE: messed up one-indexing
|
||||||
//
|
--l;
|
||||||
|
--r;
|
||||||
|
set<i64> 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() { // {{{
|
int main() { // {{{
|
||||||
cin.tie(nullptr)->sync_with_stdio(false);
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
cin.exceptions(cin.failbit);
|
cin.exceptions(cin.failbit);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
5
|
||||||
|
6
|
||||||
|
1629
|
||||||
|
13
|
||||||
|
12
|
||||||
|
520
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
Loading…
Add table
Add a link
Reference in a new issue