#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define Unique(v) sort(all(v));v.erase(unique(all(v)),v.end());
#define sz(v) ((int)v.size())
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
//#define left oooooopss
#define db(x) cerr << #x <<" == "<<x << endl;
#define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl;
#define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll b,ll e,ll m){
b%=m;
ll ans = 1;
for (; e; b = b * b % m, e /= 2)
if (e & 1) ans = ans * b % m;
return ans;
}
// debug:
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){
cerr << ' ' << H;
dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr<<"(" << #__VA_ARGS__<<"):" , dbg_out(__VA_ARGS__) , cerr << endl
#else
#define dbg(...) 42
#endif
//
int32_t main(){
fastio;
int n,q;
cin >> n >> q;
vector<ll> d(n+1);
d[0] = 0;
rep(i,1,n+1){
cin >> d[i];
if(i>1){
ll k =(d[i] + d[i-1] - 1)/(d[i-1]);
d[i] = d[i-1] * k;
}
}
sort(all(d));
auto f = [&](ll t,ll x){
ll l = 1,r=n;
for(int i=1;i<=n;i++){
int m = i;
ll D = d[m];
ll pos = (t/D) * D - m;
}
ll ans = n+1;
while(l<=r){
ll m=(l+r)/2;
ll D = d[m];
ll pos = (t/D) * D - m;
if(pos <= x){
ans = m;
r=m-1;
}else l=m+1;
}
return n-ans+1;
};
while(q--){
ll t,l,r;
cin >> t >> l >> r;
cout << f(t,r) - f(t,l-1) + (t<=r && t>=l) << endl;
}
// math -> gcd it all
// Did u check N=1? Did you switch N,M?
}
Compilation message
worst_reporter3.cpp: In lambda function:
worst_reporter3.cpp:75:10: warning: unused variable 'pos' [-Wunused-variable]
75 | ll pos = (t/D) * D - m;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
496 ms |
9168 KB |
Output is correct |
2 |
Correct |
492 ms |
9156 KB |
Output is correct |
3 |
Correct |
482 ms |
9016 KB |
Output is correct |
4 |
Correct |
476 ms |
9104 KB |
Output is correct |
5 |
Correct |
470 ms |
9048 KB |
Output is correct |
6 |
Correct |
481 ms |
9076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
496 ms |
9168 KB |
Output is correct |
2 |
Correct |
492 ms |
9156 KB |
Output is correct |
3 |
Correct |
482 ms |
9016 KB |
Output is correct |
4 |
Correct |
476 ms |
9104 KB |
Output is correct |
5 |
Correct |
470 ms |
9048 KB |
Output is correct |
6 |
Correct |
481 ms |
9076 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
303 ms |
6976 KB |
Output is correct |
14 |
Correct |
282 ms |
5188 KB |
Output is correct |
15 |
Correct |
285 ms |
7168 KB |
Output is correct |
16 |
Correct |
294 ms |
7104 KB |
Output is correct |
17 |
Correct |
375 ms |
6652 KB |
Output is correct |
18 |
Correct |
368 ms |
6664 KB |
Output is correct |
19 |
Correct |
363 ms |
6684 KB |
Output is correct |
20 |
Correct |
358 ms |
6620 KB |
Output is correct |
21 |
Correct |
373 ms |
6832 KB |
Output is correct |
22 |
Correct |
358 ms |
6592 KB |
Output is correct |
23 |
Correct |
357 ms |
6704 KB |
Output is correct |
24 |
Correct |
359 ms |
6736 KB |
Output is correct |
25 |
Correct |
496 ms |
9032 KB |
Output is correct |
26 |
Correct |
494 ms |
9024 KB |
Output is correct |
27 |
Correct |
396 ms |
7100 KB |
Output is correct |
28 |
Correct |
405 ms |
6972 KB |
Output is correct |
29 |
Correct |
399 ms |
7024 KB |
Output is correct |
30 |
Correct |
412 ms |
7092 KB |
Output is correct |
31 |
Correct |
400 ms |
7028 KB |
Output is correct |
32 |
Correct |
394 ms |
8404 KB |
Output is correct |
33 |
Correct |
1 ms |
312 KB |
Output is correct |