#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<long long> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
while (q--) {
long long x;
int l, r;
cin >> x >> l >> r;
for (int i = l; i < r; i++) {
if (b[i] == 1) {
x = (x + a[i]) % MOD;
} else {
long long licz = a[i] / (b[i] - 1);
if (x <= licz) {
x = (x + a[i]) % MOD;
} else {
x = (x * b[i]) % MOD;
}
}
}
cout << x << '\n';
}
return 0;
}
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 | #include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n >> q; vector<long long> a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } while (q--) { long long x; int l, r; cin >> x >> l >> r; for (int i = l; i < r; i++) { if (b[i] == 1) { x = (x + a[i]) % MOD; } else { long long licz = a[i] / (b[i] - 1); if (x <= licz) { x = (x + a[i]) % MOD; } else { x = (x * b[i]) % MOD; } } } cout << x << '\n'; } return 0; } |
English