#include <algorithm>
#include <cstdio>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define INT(x) int x; scanf("%d", &x)
typedef long long LL;
const int mod = 1000000007;
int a[500000], b[500000];
int main() {
INT(n);
INT(q);
REP(i,n) scanf("%d%d", &a[i], &b[i]);
REP(qq,q) {
INT(x);
INT(l);
INT(r);
int xm = x, xs = x;
FOR(i,l,r) {
if (LL(xs) + a[i] > LL(xs) * b[i]) {
xm = (xm + a[i]) % mod;
xs = min(xs + a[i], mod);
} else {
xm = LL(xm) * b[i] % mod;
xs = min(LL(xs) * b[i], LL(mod));
}
}
printf("%d\n", xm);
}
}
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 | #include <algorithm> #include <cstdio> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define INT(x) int x; scanf("%d", &x) typedef long long LL; const int mod = 1000000007; int a[500000], b[500000]; int main() { INT(n); INT(q); REP(i,n) scanf("%d%d", &a[i], &b[i]); REP(qq,q) { INT(x); INT(l); INT(r); int xm = x, xs = x; FOR(i,l,r) { if (LL(xs) + a[i] > LL(xs) * b[i]) { xm = (xm + a[i]) % mod; xs = min(xs + a[i], mod); } else { xm = LL(xm) * b[i] % mod; xs = min(LL(xs) * b[i], LL(mod)); } } printf("%d\n", xm); } } |
English