제출 #403053

#제출 시각아이디문제언어결과실행 시간메모리
40305312tqianWorst Reporter 3 (JOI18_worst_reporter3)C++17
100 / 100
737 ms33144 KiB
#include <bits/stdc++.h>

using namespace std;

#define f1r(i, a, b) for (int i = a; i < b; ++i)
#define f0r(i, a) f1r(i, 0, a)
#define each(t, a) for (auto& t : a)

#define mp make_pair
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

template <class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }


const int N = 5e5 + 5;

ll d[N];
ll a[N]; // add distance a
ll b[N]; // every time b

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n, q; cin >> n >> q;
    f0r(i, n) cin >> d[i];
    a[0] = d[0];
    b[0] = d[0];
    f1r(i, 1, n) { 
        ll ba = a[i - 1];
        ll bb = b[i - 1];
        ll times = (d[i] + a[i - 1] - 1) / a[i - 1]; // times to add
        a[i] = a[i - 1] * times;
        b[i] = b[i - 1] * times;
    }
    reverse(a, a + n);
    reverse(b, b + n);
    auto get = [&](ll t, int loc) -> ll {
        ll A = a[loc];
        ll B = b[loc];
        loc = n - 1 - loc;
        ll res = -(loc + 1);
        res += (t / B) * A;
        return res;
    };
    auto num = [&](ll t, ll bnd) -> int {
        int lo = 0;
        int hi = n - 1;
        while (hi - lo > 1) {
            int mid = (lo + hi) >> 1;
            if (get(t, mid) <= bnd) lo = mid;
            else hi = mid - 1;
        }
        if (get(t, hi) <= bnd) return hi + 1;
        else if (get(t, lo) <= bnd) return lo + 1;
        return 0;
    };
    while (q--) {
        int t, l, r; cin >> t >> l >> r;
        int ans = num(t, r) - num(t, l - 1);
        if (l <= t && t <= r) ans++;
        cout << ans << '\n';
    }
    return 0;
}

/**
 * move in left to right order at all times
 * at time t, 
 * can be described as +a every b seconds
 * so you want to find the number of people in a certain range
 * from left to right in creasing order
 * 
 */


컴파일 시 표준 에러 (stderr) 메시지

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:42:12: warning: unused variable 'ba' [-Wunused-variable]
   42 |         ll ba = a[i - 1];
      |            ^~
worst_reporter3.cpp:43:12: warning: unused variable 'bb' [-Wunused-variable]
   43 |         ll bb = b[i - 1];
      |            ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...