#include <bits/stdc++.h>
using namespace std;
const int mod = 1'000'000'007;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
int tab [n][2];
for(int i=0;i<n;i++) {
cin >> tab[i][0] >> tab[i][1];
}
long long x;
int l, r;
bool overflew;
while(q--) {
cin >> x >> l >> r;
overflew = 0;
for(int i=l;i<r;i++) {
if(overflew) {
if(tab[i][1] == 1) {
x = (x + tab[i][0]) % mod;
}
else {
x = (x * tab[i][1]) % mod;
}
}
else {
x = max(x + tab[i][0], x * tab[i][1]);
if(x > mod) {
x %= mod;
overflew = 1;
}
}
}
cout << x % mod << endl;
}
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 41 42 43 | #include <bits/stdc++.h> using namespace std; const int mod = 1'000'000'007; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, q; cin >> n >> q; int tab [n][2]; for(int i=0;i<n;i++) { cin >> tab[i][0] >> tab[i][1]; } long long x; int l, r; bool overflew; while(q--) { cin >> x >> l >> r; overflew = 0; for(int i=l;i<r;i++) { if(overflew) { if(tab[i][1] == 1) { x = (x + tab[i][0]) % mod; } else { x = (x * tab[i][1]) % mod; } } else { x = max(x + tab[i][0], x * tab[i][1]); if(x > mod) { x %= mod; overflew = 1; } } } cout << x % mod << endl; } return 0; } |
English