#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 |
1 |
Correct |
492 ms |
26740 KB |
Output is correct |
2 |
Correct |
502 ms |
26568 KB |
Output is correct |
3 |
Correct |
500 ms |
26564 KB |
Output is correct |
4 |
Correct |
491 ms |
26564 KB |
Output is correct |
5 |
Correct |
485 ms |
26516 KB |
Output is correct |
6 |
Correct |
494 ms |
26572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
460 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 |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
492 ms |
26740 KB |
Output is correct |
2 |
Correct |
502 ms |
26568 KB |
Output is correct |
3 |
Correct |
500 ms |
26564 KB |
Output is correct |
4 |
Correct |
491 ms |
26564 KB |
Output is correct |
5 |
Correct |
485 ms |
26516 KB |
Output is correct |
6 |
Correct |
494 ms |
26572 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 |
460 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 |
336 KB |
Output is correct |
13 |
Correct |
284 ms |
25172 KB |
Output is correct |
14 |
Correct |
297 ms |
25688 KB |
Output is correct |
15 |
Correct |
268 ms |
24308 KB |
Output is correct |
16 |
Correct |
293 ms |
24808 KB |
Output is correct |
17 |
Correct |
365 ms |
29236 KB |
Output is correct |
18 |
Correct |
375 ms |
29300 KB |
Output is correct |
19 |
Correct |
364 ms |
29212 KB |
Output is correct |
20 |
Correct |
368 ms |
29116 KB |
Output is correct |
21 |
Correct |
367 ms |
29112 KB |
Output is correct |
22 |
Correct |
371 ms |
29252 KB |
Output is correct |
23 |
Correct |
368 ms |
29088 KB |
Output is correct |
24 |
Correct |
370 ms |
29232 KB |
Output is correct |
25 |
Correct |
483 ms |
26636 KB |
Output is correct |
26 |
Correct |
482 ms |
26636 KB |
Output is correct |
27 |
Correct |
408 ms |
28736 KB |
Output is correct |
28 |
Correct |
412 ms |
29180 KB |
Output is correct |
29 |
Correct |
400 ms |
28604 KB |
Output is correct |
30 |
Correct |
406 ms |
28740 KB |
Output is correct |
31 |
Correct |
407 ms |
28964 KB |
Output is correct |
32 |
Correct |
383 ms |
25208 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |