This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define INF 1e18
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector < pair<ll, ll> > vii;
typedef long double ld;
typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
ll d[511111];
ll t[511111];
ll mov[511111];
vii a;
int main()
{
ios_base::sync_with_stdio(false) ;
cin.tie(NULL);
//freopen("stress.txt","w",stdout);
ll n, q;
cin >> n >> q;
t[0]=1;
mov[0]=1;
for(int i = 1; i <= n; i++){
cin >> d[i];
}
ll idx=0;
ll cnt=1;
for(int i = 1; i <= n; i++){
ll x = ((d[i]+mov[i-1]-1)/mov[i-1]);
t[i]=x*t[i-1];
mov[i]=x*mov[i-1];
//cout << t[i] << " " << mov[i] << endl;
if(x==1){
cnt++;
}
else{
if(t[idx]<=1e9){
a.pb(mp(idx,cnt));
idx=i;
cnt=1;
}
else{
i=n;
}
}
}
a.pb(mp(idx,cnt));
ll T, L, R, l, r;
for(int i = 0; i < q; i++){
cin >> T >> L >> R;
ll ans = 0;
for(int j = 0; j < int(a.size()); j++){
r = -(a[j].fi)+T/t[a[j].fi]*mov[a[j].fi];
l = r-a[j].se+1;
ans+=max(ll(0),min(R,r)-max(L,l)+1);
}
cout << ans << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |