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>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;
long long INF=LLONG_MAX;
ll n,q,d[511111],chg[511111];
ll md=0;
void upd(){
ll ptr = d[1];
for(ll i = 2; i <= n; i++){
if(d[i]<=d[i-1]){
chg[i] = 1;
}
}
ll pt = 0;
for(ll i = 1; i <= n; i++){
if(chg[i])d[i] = d[i-1];
else{
if(d[i]==md)pt=i;
ll cur = d[i]/ptr;
if(d[i]%ptr)cur++;
d[i] = ptr*cur;
ptr = d[i];
if(pt)break;
}
}
for(ll i = pt+1; i <= n; i++)d[i]=ptr;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
cin >> n >> q;
for(int i = 1; i <= n; i++){
cin >> d[i];
md = max(md,d[i]);
}
upd();
ll ti,le,ri;
//for(int i = 1; i <= n; i++)cout << d[i] << ' ';
//cout << endl;
while(q--){
cin >> ti >> le >> ri;
ll ans = 0;
if(ti>=le&&ti<=ri){
ans++;
}
for(int i = 1; i <= n; i++){
ll cur = ti/d[i];
ll pos = -1*i + cur*d[i];
if(pos>=le&&pos<=ri){
ans++;
}
//cout << cur << ' ' << pos << ' ' << ans << endl;
}
cout << ans << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |