#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll BASE = 1000000007;
ll n, q, x, l, r;
ll a[500000];
ll b[500000];
bool duzy;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> q;
for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
for (int _ = 0; _ < q; _++)
{
cin >> x >> l >> r;
duzy = false;
for (int i = l; i < r; i++)
{
if (a[i] == 0) x *= b[i];
else if (b[i] == 1) x += a[i];
else if (duzy) x *= b[i];
else if (a[i] < x*(b[i]-1)) x *= b[i];
else x += a[i];
if (x >= BASE) duzy = true;
x %= BASE;
}
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 | #include <bits/stdc++.h> using namespace std; typedef long long ll; constexpr ll BASE = 1000000007; ll n, q, x, l, r; ll a[500000]; ll b[500000]; bool duzy; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> q; for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; for (int _ = 0; _ < q; _++) { cin >> x >> l >> r; duzy = false; for (int i = l; i < r; i++) { if (a[i] == 0) x *= b[i]; else if (b[i] == 1) x += a[i]; else if (duzy) x *= b[i]; else if (a[i] < x*(b[i]-1)) x *= b[i]; else x += a[i]; if (x >= BASE) duzy = true; x %= BASE; } cout << x << '\n'; } return 0; } |
English