#include <cstdio>
static constexpr unsigned long long MODULO = 1000000007UL;
typedef struct {
unsigned a, b;
} pair_t;
int main(void)
{
unsigned n, q;
static pair_t axis[500000];
scanf("%u%u", &n, &q);
for (unsigned i = 0; i < n; i++)
scanf("%u%u", &axis[i].a, &axis[i].b);
for (unsigned i = 0; i < q; i++) {
unsigned x, l, r;
scanf("%u%u%u", &x, &l, &r);
unsigned long long lx = x;
long double ld = x;
for (unsigned j = l; j < r; j++) {
long double lda = ld + axis[j].a;
long double ldb = ld * axis[j].b;
if (lda > ldb) {
ld = lda;
lx = (lx + axis[j].a) % MODULO;
} else {
ld = ldb;
lx = (lx * axis[j].b) % MODULO;
}
}
printf("%llu\n", lx);
}
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 | #include <cstdio> static constexpr unsigned long long MODULO = 1000000007UL; typedef struct { unsigned a, b; } pair_t; int main(void) { unsigned n, q; static pair_t axis[500000]; scanf("%u%u", &n, &q); for (unsigned i = 0; i < n; i++) scanf("%u%u", &axis[i].a, &axis[i].b); for (unsigned i = 0; i < q; i++) { unsigned x, l, r; scanf("%u%u%u", &x, &l, &r); unsigned long long lx = x; long double ld = x; for (unsigned j = l; j < r; j++) { long double lda = ld + axis[j].a; long double ldb = ld * axis[j].b; if (lda > ldb) { ld = lda; lx = (lx + axis[j].a) % MODULO; } else { ld = ldb; lx = (lx * axis[j].b) % MODULO; } } printf("%llu\n", lx); } return 0; } |
English