Submission #205144

# Submission time Handle Problem Language Result Execution time Memory
205144 2020-02-28T07:31:08 Z egekabas Worst Reporter 3 (JOI18_worst_reporter3) C++14
100 / 100
1008 ms 32760 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long   ll;
typedef unsigned long long   ull;
typedef long double ld;
typedef pair<ll, ll>    pll;
typedef pair<ull, ull>    pull;
typedef pair<int, int>  pii;
typedef pair<ld, ld>  pld;
ll n, q;
ll slow[500009];
pll rate[500009];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    cin >> n >> q;
    for(ll i = 1; i <= n; ++i)
        cin >> slow[i];
    rate[0] = {1, 1};
    for(ll i = 1; i <= n; ++i){
        ll times = (slow[i]+rate[i-1].ff-1)/rate[i-1].ff;
        rate[i].ff = times*rate[i-1].ff;
        rate[i].ss = times*rate[i-1].ss;
    }
    while(q--){
        ll t, l, r;
        cin >> t >> l >> r;
        
        ll l1 = -1, r1 = n;
        while(l1 < r1){
            ll m = (l1+r1+1)/2;
            ll dist = t/rate[m].ss*rate[m].ff-m;
            if(dist >= l)
                l1 = m;
            else
                r1 = m-1;
        }
        ll l2 = 0, r2 = n+1;
        while(l2 < r2){
            ll m = (l2+r2)/2;
            ll dist = t/rate[m].ss*rate[m].ff-m;
            if(dist <= r)
                r2 = m;
            else
                l2 = m+1;
        }
        if(l1 == -1 || l2 == n+1)
            cout << "0\n";
        else
            cout << l1-l2+1 << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 843 ms 30712 KB Output is correct
2 Correct 843 ms 30536 KB Output is correct
3 Correct 850 ms 30932 KB Output is correct
4 Correct 1008 ms 30480 KB Output is correct
5 Correct 1002 ms 30632 KB Output is correct
6 Correct 886 ms 30588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
3 Correct 6 ms 432 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 6 ms 380 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 843 ms 30712 KB Output is correct
2 Correct 843 ms 30536 KB Output is correct
3 Correct 850 ms 30932 KB Output is correct
4 Correct 1008 ms 30480 KB Output is correct
5 Correct 1002 ms 30632 KB Output is correct
6 Correct 886 ms 30588 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 6 ms 432 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 6 ms 380 KB Output is correct
12 Correct 6 ms 376 KB Output is correct
13 Correct 427 ms 29032 KB Output is correct
14 Correct 436 ms 29728 KB Output is correct
15 Correct 409 ms 28452 KB Output is correct
16 Correct 426 ms 28792 KB Output is correct
17 Correct 556 ms 26108 KB Output is correct
18 Correct 560 ms 25996 KB Output is correct
19 Correct 563 ms 25464 KB Output is correct
20 Correct 559 ms 25984 KB Output is correct
21 Correct 573 ms 25720 KB Output is correct
22 Correct 567 ms 25464 KB Output is correct
23 Correct 546 ms 26232 KB Output is correct
24 Correct 550 ms 25720 KB Output is correct
25 Correct 828 ms 30712 KB Output is correct
26 Correct 837 ms 30584 KB Output is correct
27 Correct 615 ms 32760 KB Output is correct
28 Correct 607 ms 28488 KB Output is correct
29 Correct 579 ms 32560 KB Output is correct
30 Correct 695 ms 32632 KB Output is correct
31 Correct 611 ms 29280 KB Output is correct
32 Correct 591 ms 29176 KB Output is correct
33 Correct 5 ms 376 KB Output is correct