# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
220210 | patrikpavic2 | Worst Reporter 3 (JOI18_worst_reporter3) | C++17 | 582 ms | 25648 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#define X first
#define Y second
#define PB push_back
using namespace std;
typedef long long ll;
const int N = 5e5 + 500;
ll D[N];
int n, q, nxt[N];
int kolko(ll T,ll L,ll R){
ll tren = T;
int ans = 0;
for(int i = 0;i <= n;i = nxt[i]){
ll R2 = tren * D[i] - i, L2 = tren * D[i] - nxt[i] + 1;
if(max(L, L2) <= min(R, R2))
ans += min(R, R2) - max(L, L2) + 1;
if(nxt[i] <= n)
tren = tren / (D[nxt[i]] / D[i]);
if(!tren)
break;
}
return ans;
}
int main(){
scanf("%d%d", &n, &q);
D[0] = 1;
for(int i = 1;i <= n;i++){
scanf("%lld", D + i);
if(D[i] < D[i - 1])
D[i] = D[i - 1];
else if(D[i] % D[i - 1])
D[i] += D[i - 1] - D[i] % D[i - 1];
}
int lst = 0;
for(int i = 1;i <= n;i++){
if(D[i] != D[lst]){
nxt[lst] = i;
lst = i;
}
}
nxt[lst] = n + 1;
for(;q--;){
ll A, B, C; scanf("%lld%lld%lld", &A, &B, &C);
printf("%d\n", kolko(A, B, C));
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |