Submission #1094654

#TimeUsernameProblemLanguageResultExecution timeMemory
1094654thangdz2k7Worst Reporter 3 (JOI18_worst_reporter3)C++17
100 / 100
339 ms23416 KiB
// author : thembululquaUwU
// 3.9.2024

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define endl '\n'

using namespace std;
using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;

const int N = 5e5 + 5;
const int mod = 1e9 + 7;

void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}

int n, a[N], q;

int fd(int t, int up){
    int l = 0, r = n, ans = n + 1;
    while (l <= r){
        int m = l + r >> 1;
        if (t / a[m] * a[m] - m <= up) ans = m, r = m - 1;
        else l = m + 1;
    }
    return n - ans;
}

void solve(){
    cin >> n >> q;
    a[0] = 1;
    for (int i = 1; i <= n; ++ i){
        cin >> a[i];
        a[i] = ((a[i] - 1) / a[i - 1] + 1) * a[i - 1];
    }

    while (q --){
        int t, l, r; cin >> t >> l >> r;
        cout << fd(t, r) - fd(t, l - 1) << endl;
    }
}

int main(){
    if (fopen("pqh.inp", "r")){
        freopen("pqh.inp", "r", stdin);
        freopen("pqh.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t = 1; // cin >> t;
    while (t --) solve();
    return 0;
}

Compilation message (stderr)

worst_reporter3.cpp:18:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void maxl(auto &a, auto b) {a = max(a, b);}
      |           ^~~~
worst_reporter3.cpp:18:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void maxl(auto &a, auto b) {a = max(a, b);}
      |                    ^~~~
worst_reporter3.cpp:19:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void minl(auto &a, auto b) {a = min(a, b);}
      |           ^~~~
worst_reporter3.cpp:19:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void minl(auto &a, auto b) {a = min(a, b);}
      |                    ^~~~
worst_reporter3.cpp: In function 'int fd(int, int)':
worst_reporter3.cpp:26:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   26 |         int m = l + r >> 1;
      |                 ~~^~~
worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen("pqh.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
worst_reporter3.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         freopen("pqh.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...