#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define tak cout<<"TAK\n"
#define yes cout<<"YES\n"
#define nie cout<<"NIE\n"
#define no cout<<"NO\n"
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
using pdd = pair<ld,ld>;
#define vec vector
#define all(x) (x).begin(), (x).end()
#define sz(x) (x).size()
#define linijki ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mapa map<ll,ll>
#define umapa unordered_map<ll,ll>
#define se set<ll>
#define ff first
#define ss second
#define str string
const ll alph = 26;
const ll BIN6 = (1LL << 20);
const ll BIN9 = (1LL << 30);
const ll BIN18 = (1LL << 60);
const ll INF5 = 100000;
const ll INF6 = 1000000;
const ll INF9 = 1000000000;
const ll INF18 = 1000000000000000000;
const ld DINF5 = 1e5L;
const ld DINF6 = 1e6L;
const ld DINF9 = 1e9L;
const ll MOD = 1000000007;
vec<pll> ruchy;
void solve(){
ll x, l, r;
cin>>x>>l>>r;
ll wyn =x;
for(int i=l;i<r;++i){
wyn=max(wyn+ruchy[i].ff, wyn*ruchy[i].ss);
wyn = wyn%MOD;
}
wyn = wyn%MOD;
cout<<wyn<<"\n";
}
int main() {
linijki;
ll n, q;
cin >> n >> q;
ruchy.resize(n);
for(int i=0;i<n;++i){
cin>>ruchy[i].ff>>ruchy[i].ss;
}
while(q--){
solve();
}
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #include <bits/stdc++.h> using namespace std; #define pb push_back #define tak cout<<"TAK\n" #define yes cout<<"YES\n" #define nie cout<<"NIE\n" #define no cout<<"NO\n" using ll = long long; using ld = long double; using pll = pair<ll,ll>; using pdd = pair<ld,ld>; #define vec vector #define all(x) (x).begin(), (x).end() #define sz(x) (x).size() #define linijki ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define mapa map<ll,ll> #define umapa unordered_map<ll,ll> #define se set<ll> #define ff first #define ss second #define str string const ll alph = 26; const ll BIN6 = (1LL << 20); const ll BIN9 = (1LL << 30); const ll BIN18 = (1LL << 60); const ll INF5 = 100000; const ll INF6 = 1000000; const ll INF9 = 1000000000; const ll INF18 = 1000000000000000000; const ld DINF5 = 1e5L; const ld DINF6 = 1e6L; const ld DINF9 = 1e9L; const ll MOD = 1000000007; vec<pll> ruchy; void solve(){ ll x, l, r; cin>>x>>l>>r; ll wyn =x; for(int i=l;i<r;++i){ wyn=max(wyn+ruchy[i].ff, wyn*ruchy[i].ss); wyn = wyn%MOD; } wyn = wyn%MOD; cout<<wyn<<"\n"; } int main() { linijki; ll n, q; cin >> n >> q; ruchy.resize(n); for(int i=0;i<n;++i){ cin>>ruchy[i].ff>>ruchy[i].ss; } while(q--){ solve(); } return 0; } |
English