Submission #968018

# Submission time Handle Problem Language Result Execution time Memory
968018 2024-04-23T06:56:31 Z Tuanlinh123 Worst Reporter 3 (JOI18_worst_reporter3) C++17
100 / 100
467 ms 29280 KB
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
#define sz(a) ((ll)(a).size())
using namespace std;

const ll maxn=500005;
ll d[maxn], inc[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, q; cin >> n >> q;
    for (ll i=1; i<=n; i++) cin >> d[i];
    for (ll i=0; i<=n; i++) inc[i]=i?(d[i]+inc[i-1]-1)/inc[i-1]*inc[i-1]:1;
    auto find=[&](ll idx, ll t){return -idx+t/inc[idx]*inc[idx];};
    for (ll i=1; i<=q; i++)
    {
        ll t, l, r; cin >> t >> l >> r;
        ll fir=0, las=0;
        // find first <=r
        {
            ll lo=0, hi=n+1;
            while (hi>lo)
            {
                ll mid=(lo+hi)/2;
                if (find(mid, t)<=r) hi=mid;
                else lo=mid+1;
            }
            fir=lo;
        }
        // find last >=l
        {
            ll lo=-1, hi=n;
            while (hi>lo)
            {
                ll mid=(lo+hi+1)/2;
                if (find(mid, t)>=l) lo=mid;
                else hi=mid-1;
            }
            las=lo;
        }
        cout << las-fir+1 << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 436 ms 26708 KB Output is correct
2 Correct 433 ms 26516 KB Output is correct
3 Correct 439 ms 26708 KB Output is correct
4 Correct 453 ms 26708 KB Output is correct
5 Correct 467 ms 26692 KB Output is correct
6 Correct 441 ms 26716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 436 ms 26708 KB Output is correct
2 Correct 433 ms 26516 KB Output is correct
3 Correct 439 ms 26708 KB Output is correct
4 Correct 453 ms 26708 KB Output is correct
5 Correct 467 ms 26692 KB Output is correct
6 Correct 441 ms 26716 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 264 ms 25236 KB Output is correct
14 Correct 252 ms 25820 KB Output is correct
15 Correct 244 ms 24256 KB Output is correct
16 Correct 250 ms 24900 KB Output is correct
17 Correct 322 ms 29100 KB Output is correct
18 Correct 323 ms 29248 KB Output is correct
19 Correct 318 ms 29152 KB Output is correct
20 Correct 328 ms 29192 KB Output is correct
21 Correct 333 ms 29264 KB Output is correct
22 Correct 328 ms 29152 KB Output is correct
23 Correct 335 ms 29268 KB Output is correct
24 Correct 327 ms 29280 KB Output is correct
25 Correct 453 ms 26844 KB Output is correct
26 Correct 443 ms 26708 KB Output is correct
27 Correct 365 ms 28776 KB Output is correct
28 Correct 372 ms 29100 KB Output is correct
29 Correct 373 ms 28684 KB Output is correct
30 Correct 373 ms 28900 KB Output is correct
31 Correct 358 ms 29120 KB Output is correct
32 Correct 337 ms 25136 KB Output is correct
33 Correct 1 ms 2392 KB Output is correct