#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;
#define ll long long
const ll mod = 1e9 + 7;
ll tab[500'007][2];
void func(ll& n)
{
register ll c;
n = 0;
c = getchar();
while (c > 47 && c < 58)
{
n = n * 10 + c - 48;
c = getchar();
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(nullptr);
ll n, q;
func(n);
func(q);
ll x,l,r;
for (int i = 0; i < n; i++)
{
func(tab[i][0]);
func(tab[i][1]);
}
while (q--)
{
func(x);
func(l);
func(r);
for (int i = l; i < r; i++)
{
//cout << "|" << x << " " << tab[i][0]<<" "<< tab[i][1]<< '\n';
if (x > tab[i][0] and tab[i][1] != 1)
x = ((x % mod) * tab[i][1]) % mod;
else
x = ((x % mod) + tab[i][0]) % mod;
}
cout << x << '\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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #include <iostream> #include <vector> #include <algorithm> #include <stdio.h> using namespace std; #define ll long long const ll mod = 1e9 + 7; ll tab[500'007][2]; void func(ll& n) { register ll c; n = 0; c = getchar(); while (c > 47 && c < 58) { n = n * 10 + c - 48; c = getchar(); } } int main() { ios::sync_with_stdio(0); cin.tie(nullptr); ll n, q; func(n); func(q); ll x,l,r; for (int i = 0; i < n; i++) { func(tab[i][0]); func(tab[i][1]); } while (q--) { func(x); func(l); func(r); for (int i = l; i < r; i++) { //cout << "|" << x << " " << tab[i][0]<<" "<< tab[i][1]<< '\n'; if (x > tab[i][0] and tab[i][1] != 1) x = ((x % mod) * tab[i][1]) % mod; else x = ((x % mod) + tab[i][0]) % mod; } cout << x << '\n'; } } |
English