-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextext.cpp
67 lines (50 loc) · 1.2 KB
/
extext.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using vpi = vector<pi>;
using vb = vector<bool>;
const ll mod = 998244353;
void solve() {
ll n;
cin >> n;
vi a(n);
for (ll i = 0; i < n; i++) {
cin >> a[i];
}
vpi f;
ll ans = 0;
ll num_break = 0;
for (ll i = n - 1; i >= 0; i--) {
vpi f2;
ll bk = 0;
for (pi it : f) {
ll v = it.first;
ll cnt = it.second;
ll x = ceil((double)a[i] / v);
ll first = floor((double)a[i] / x);
if (first != bk) f2.push_back({first, 0});
bk = first;
f2.back().second += cnt;
num_break += (cnt % mod) * (x - 1);
num_break %= mod;
}
reverse(f2.begin(), f2.end());
ll first = a[i];
if (f2.size() == 0 || first != f2.back().first) f2.push_back({first, 0});
f2.back().second++;
ans += num_break;
ans %= mod;
f = f2;
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin >> t;
while (t--) solve();
return 0;
}