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