Submission #774737

# Submission time Handle Problem Language Result Execution time Memory
774737 2023-07-06T02:24:29 Z vjudge1 Worst Reporter 3 (JOI18_worst_reporter3) C++17
100 / 100
442 ms 7264 KB
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/

#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define isz(x) (int)x.size()
using namespace std;

const int mxN = 5e5 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;

int n, q, speed[mxN];

void solve() {
    cin >> n >> q; speed[0] = 1;
    for(int i = 1; i <= n; ++i) {
        int val; cin >> val;
        if(speed[i - 1] == mod) {
            speed[i] = mod;
            continue;
        }
        int needed = val / speed[i - 1];
        if(needed * speed[i - 1] < val) ++needed;
        if(mod / needed < speed[i - 1]) speed[i] = mod;
        else speed[i] = speed[i - 1] * needed;
    }
    for(int i = 1; i <= q; ++i) {
        int t, l, r; cin >> t >> l >> r;
        int tl = 0, tr = n, ansl = -1, ansr = -1;
        while(tl <= tr) {
            int mid = (tl + tr) >> 1;
            if(speed[mid] == -1) tr = mid - 1;
            else {
                int len = (t / speed[mid]) * speed[mid] - mid;
                if(len >= l) tl = mid + 1;
                else tr = mid - 1;
            }
        }
        if(tr < 0) {
            cout << 0 << "\n";
            continue;
        }
        else ansl = tr;

        tl = 0, tr = n;
        while(tl <= tr) {
            int mid = (tl + tr) >> 1;
            if(speed[mid] == -1) tr = mid - 1;
            else {
                int len = (t / speed[mid]) * speed[mid] - mid;
                // cout << len << " " << t << " " << speed[mid] << endl;
                if(len <= r) tr = mid - 1;
                else tl = mid + 1;
            }
        }
        // cout << ansl << " " << tl << endl;
        if(tl > ansl) cout << 0 << "\n";
        else cout << ansl - tl + 1 << "\n";
    }
}

signed main() {

#ifndef CDuongg
    if(fopen(taskname".inp", "r"))
        assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
    freopen("bai3.inp", "r", stdin);
    freopen("bai3.out", "w", stdout);
    auto start = chrono::high_resolution_clock::now();
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1; //cin >> t;
    while(t--) solve();

#ifdef CDuongg
    auto end = chrono::high_resolution_clock::now();
    cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
    cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif

}

Compilation message

worst_reporter3.cpp: In function 'void solve()':
worst_reporter3.cpp:43:40: warning: unused variable 'ansr' [-Wunused-variable]
   43 |         int tl = 0, tr = n, ansl = -1, ansr = -1;
      |                                        ^~~~
# Verdict Execution time Memory Grader output
1 Correct 421 ms 7264 KB Output is correct
2 Correct 420 ms 7168 KB Output is correct
3 Correct 418 ms 7252 KB Output is correct
4 Correct 422 ms 7200 KB Output is correct
5 Correct 424 ms 7200 KB Output is correct
6 Correct 442 ms 7180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 421 ms 7264 KB Output is correct
2 Correct 420 ms 7168 KB Output is correct
3 Correct 418 ms 7252 KB Output is correct
4 Correct 422 ms 7200 KB Output is correct
5 Correct 424 ms 7200 KB Output is correct
6 Correct 442 ms 7180 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 250 ms 5168 KB Output is correct
14 Correct 251 ms 5196 KB Output is correct
15 Correct 245 ms 5156 KB Output is correct
16 Correct 263 ms 5228 KB Output is correct
17 Correct 313 ms 6540 KB Output is correct
18 Correct 325 ms 6540 KB Output is correct
19 Correct 309 ms 6476 KB Output is correct
20 Correct 319 ms 6604 KB Output is correct
21 Correct 312 ms 6648 KB Output is correct
22 Correct 318 ms 6604 KB Output is correct
23 Correct 316 ms 6648 KB Output is correct
24 Correct 315 ms 6604 KB Output is correct
25 Correct 423 ms 7136 KB Output is correct
26 Correct 416 ms 7148 KB Output is correct
27 Correct 364 ms 7128 KB Output is correct
28 Correct 335 ms 6860 KB Output is correct
29 Correct 338 ms 7040 KB Output is correct
30 Correct 344 ms 7048 KB Output is correct
31 Correct 368 ms 6952 KB Output is correct
32 Correct 326 ms 6716 KB Output is correct
33 Correct 0 ms 212 KB Output is correct