#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],per[511111];
ll md=0;
vector < pair<ll, pll> > seg;
void upd(){
ll cur = d[1], pre = 1;
per[1] = d[1];
for(ll i = 2; i <= n; i++){
ll tm = (cur>=d[i]?1:d[i]/cur+(d[i]%cur?1:0));
per[i] = tm*cur;
if(per[i]>cur){
seg.pb(mp(cur,mp(pre,i-1)));
pre = i;
cur = per[i];
}
}
seg.pb(mp(cur,mp(pre,n)));
}
ll solve(ll ti, ll x, ll y){
ll ans = 0;
if(ti>=x&&ti<=y)ans++;
for(int i = 0; i < seg.size(); i++){
ll cur = seg[i].fi; ll le = seg[i].se.fi; ll ri = seg[i].se.se;
ll moves = (ti/cur)*cur;
ll pos_l = -1*ri; ll pos_r = -1*le;
pos_l += moves; pos_r += moves;
pos_l=max(pos_l,x);
pos_r=min(pos_r,y);
if(pos_l>=x&&pos_l<=y&&pos_r>=x&&pos_r<=y){
ans += pos_r-pos_l+1;
}
}
return ans;
}
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;
while(q--){
cin >> ti >> le >> ri;
ll ans = 0;
ans += solve(ti,le,ri);
cout << ans << endl;
}
}
Compilation message
worst_reporter3.cpp: In function 'll solve(ll, ll, ll)':
worst_reporter3.cpp:43:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < seg.size(); i++){
~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1603 ms |
15456 KB |
Output is correct |
2 |
Correct |
1609 ms |
15320 KB |
Output is correct |
3 |
Correct |
1608 ms |
15436 KB |
Output is correct |
4 |
Correct |
1615 ms |
15440 KB |
Output is correct |
5 |
Correct |
1612 ms |
15460 KB |
Output is correct |
6 |
Correct |
1605 ms |
15472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
380 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1603 ms |
15456 KB |
Output is correct |
2 |
Correct |
1609 ms |
15320 KB |
Output is correct |
3 |
Correct |
1608 ms |
15436 KB |
Output is correct |
4 |
Correct |
1615 ms |
15440 KB |
Output is correct |
5 |
Correct |
1612 ms |
15460 KB |
Output is correct |
6 |
Correct |
1605 ms |
15472 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
380 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
1628 ms |
13684 KB |
Output is correct |
14 |
Correct |
1618 ms |
13696 KB |
Output is correct |
15 |
Correct |
1614 ms |
13192 KB |
Output is correct |
16 |
Correct |
1618 ms |
13460 KB |
Output is correct |
17 |
Correct |
1817 ms |
15368 KB |
Output is correct |
18 |
Correct |
1793 ms |
15208 KB |
Output is correct |
19 |
Correct |
1812 ms |
15372 KB |
Output is correct |
20 |
Correct |
1811 ms |
15132 KB |
Output is correct |
21 |
Correct |
1815 ms |
14752 KB |
Output is correct |
22 |
Correct |
1799 ms |
14576 KB |
Output is correct |
23 |
Correct |
1811 ms |
14648 KB |
Output is correct |
24 |
Correct |
1808 ms |
14656 KB |
Output is correct |
25 |
Correct |
1629 ms |
14508 KB |
Output is correct |
26 |
Correct |
1615 ms |
13812 KB |
Output is correct |
27 |
Correct |
1817 ms |
14084 KB |
Output is correct |
28 |
Correct |
1837 ms |
13880 KB |
Output is correct |
29 |
Correct |
1847 ms |
15804 KB |
Output is correct |
30 |
Correct |
1826 ms |
14256 KB |
Output is correct |
31 |
Correct |
1831 ms |
14172 KB |
Output is correct |
32 |
Correct |
1608 ms |
13700 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |