제출 #1332984

#제출 시각아이디문제언어결과실행 시간메모리
1332984icebearWorst Reporter 3 (JOI18_worst_reporter3)C++20
100 / 100
403 ms19112 KiB
/* AUTHOR: TUAN ANH - BUI */
// ~~ icebear ~~
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

template<class X, class Y>
    bool minimize(X &x, const Y &y) {
        if (x > y) return x = y, true;
        return false;
    }

template<class X, class Y>
    bool maximize(X &x, const Y &y) {
        if (x < y) return x = y, true;
        return false;
    }

#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define MASK(i) (1LL << (i))
#define BIT(S, i) (((S) >> (i)) & 1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "icebear"
/*END OF TEMPLATE. ICEBEAR AND THE CAT WILL WIN TST26 */

const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 27092008;
const ll INF  = (ll)1e18 + 27092008;
const int N = 5e5 + 5;
int n, q;
ll pos[N], dist_per_move[N], time_per_move[N], require_dist[N];

int f(int t, int r) {
    int low = 0, high = n;
    while(low <= high) {
        int mid = (low + high) >> 1;
        if (pos[mid] + (t / time_per_move[mid]) * dist_per_move[mid] > r) low = mid + 1;
        else high = mid - 1;
    }
    return n - low + 1;
}

void init(void) {
    cin >> n >> q;
    FOR(i, 1, n) cin >> require_dist[i];
    FOR(i, 0, n) pos[i] = -i;
    dist_per_move[0] = time_per_move[0] = 1;
}

void process(void) {
    FOR(i, 1, n) {
        ll move_require = (require_dist[i] + dist_per_move[i - 1] - 1) / dist_per_move[i - 1];
        time_per_move[i] = move_require * time_per_move[i - 1];
        dist_per_move[i] = pos[i - 1] + move_require * dist_per_move[i - 1] - 1 - pos[i];
    }
    while(q--) {
        int t, l, r;
        cin >> t >> l >> r;
        cout << f(t, r) - f(t, l - 1) << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if (fopen(task".inp", "r")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int tc = 1;
//    cin >> tc;
    while(tc--) {
        init();
        process();
    }
    return 0;
}

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

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
worst_reporter3.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...