This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast")
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 5e5 + 10;
const int MOD = 1e9 + 7;
#define int long long
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int n, q;
int d[MAXN];
int freq[MAXN];
int f(int player, int tim) {
int cycles = tim / freq[player];
int dist = cycles * freq[player];
return -player + dist;
}
void solve(int tc) {
cin >> n >> q;
for(int i=1; i<=n; i++) cin >> d[i];
freq[0] = 1;
freq[1] = d[1];
for(int i=2; i<=n; i++) freq[i] = ((d[i] + freq[i-1] - 1) / freq[i-1]) * freq[i-1];
while(q--) {
int t, l, r;
cin >> t >> l >> r;
int lb = 0, rb = n;
while(lb < rb) {
int mid = (lb + rb) >> 1;
if(f(mid, t) <= r) rb = mid;
else lb = mid + 1;
}
int lb2 = 0, rb2 = n;
while(lb2 < rb2) {
int mid = (lb2 + rb2 + 1) >> 1;
if(f(mid, t) >= l) lb2 = mid;
else rb2 = mid - 1;
}
if(lb <= lb2 && f(lb, t) >= l && f(lb, t) <= r && f(lb2, t) >= l && f(lb2, t) <= r) cout << lb2 - lb + 1 << "\n";
else cout << "0\n";
}
}
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |