Submission #441874

#TimeUsernameProblemLanguageResultExecution timeMemory
441874dutchWorst Reporter 3 (JOI18_worst_reporter3)C++17
100 / 100
787 ms11332 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int INF = 2e9, MAXN = 5e5; int n, q, d[MAXN], s[MAXN]; int search(int x, int p){ int i = -1; p -= x; for(int j=1<<20; j/=2; ) if(i+j < n && -i-j-x%s[i+j] > p) i += j; return i; } signed main(){ cin.tie(0)->sync_with_stdio(0); cin >> n >> q; for(int i=0; i<n; ++i) cin >> d[i]; fill(s, s+n, INF); s[0] = d[0]; for(int i=1; i<n && s[i-1] < INF; ++i) s[i] = ((d[i] + s[i-1] - 1) / s[i-1]) * s[i-1]; while(q--){ int x, l, r; cin >> x >> l >> r; cout << search(x, l) - search(x, r+1) + (l <= x && x <= r) << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...