답안 #1029957

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1029957 2024-07-21T14:37:21 Z underwaterkillerwhale Worst Reporter 3 (JOI18_worst_reporter3) C++17
100 / 100
348 ms 15352 KB
#include <bits/stdc++.h>
#define se              second
#define fs              first
#define mp              make_pair
#define pb              push_back
#define ll              long long
#define ii              pair<ll,ll>
#define ld              long double
#define SZ(v)           (int)v.size()
#define ALL(v)          v.begin(), v.end()
#define bit(msk, i)     ((msk >> i) & 1)
#define iter(id, v)     for(auto id : v)
#define rep(i,m,n)      for(int i=(m); i<=(n); i++)
#define reb(i,m,n)      for(int i=(m); i>=(n); i--)
using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now().time_since_epoch().count());
ll Rand(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rd); }

const int N = 5e5 + 7;
const int Mod = 1e9 + 7;
const int szBL = 320;
const ll INF = 1e9 + 160907;
const int BASE = 1337;

int n, Q, m;
int D[N];
int dp[N];
int T[N], L[N], R[N];
map<int, pair<int,int>> itv;

void solution () {
    cin >> n >> Q;
    ++n;
    D[1] = 1;
    rep (i, 2, n) {
        cin >> D[i];
    }
    dp[1] = 1;
    vector<int> vals;
    vals.push_back(1);
    itv[1] = {1, 1};
    rep (i, 2, n) {
        dp[i] = min (INF, (ll) (dp[i - 1] * ceil(1.0 * D[i] / D[i - 1])));
        D[i] = min (INF, (ll) (ceil(1.0 * D[i] / D[i - 1]) * D[i - 1]));
        vals.push_back(dp[i]);
        if (itv[dp[i]].fs == 0) itv[dp[i]] = {i, i};
        else itv[dp[i]].se = i;
    }
    sort (ALL(vals));
    vals.resize (m = unique(ALL(vals)) - vals.begin());
    rep (i, 1, Q) {
        cin >> T[i] >> L[i] >> R[i];
        int res = 0;
        iter (&vl, vals) {
            int lf = itv[vl].fs, rt = itv[vl].se;
            int bL = max(1LL * lf, 1LL * (T[i] / vl) * D[lf] + 1 - R[i]);
            int bR = min(1LL * rt, 1LL * (T[i] / vl) * D[lf] + 1 - L[i]);
            res += max(0, bR - bL + 1);
        }
        cout << res <<"\n";
    }
}

#define file(name) freopen(name".inp", "r", stdin); \
freopen(name".out", "w", stdout);

int main () {
//    file("c");
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll num_Test = 1;
//    cin >> num_Test;
    while(num_Test--)
        solution();
}
/*
nếu mình nghĩ sẽ thay đổi định nghĩa, kiểu dữ liệu của hàm hay mảng j thì mình phải nghĩ xem nó sẽ ảnh hưởng đến các phần nào
nghĩ xem mình có thể làm gì, có khả năng làm những gì với giới hạn bài toán, đặc điểm bài toans
0 0
1 0
0 0
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 213 ms 15152 KB Output is correct
2 Correct 184 ms 15272 KB Output is correct
3 Correct 192 ms 15300 KB Output is correct
4 Correct 166 ms 15304 KB Output is correct
5 Correct 193 ms 15352 KB Output is correct
6 Correct 178 ms 15120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 213 ms 15152 KB Output is correct
2 Correct 184 ms 15272 KB Output is correct
3 Correct 192 ms 15300 KB Output is correct
4 Correct 166 ms 15304 KB Output is correct
5 Correct 193 ms 15352 KB Output is correct
6 Correct 178 ms 15120 KB Output is correct
7 Correct 2 ms 8536 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 178 ms 13132 KB Output is correct
14 Correct 161 ms 13252 KB Output is correct
15 Correct 170 ms 13120 KB Output is correct
16 Correct 179 ms 13200 KB Output is correct
17 Correct 305 ms 14556 KB Output is correct
18 Correct 308 ms 14532 KB Output is correct
19 Correct 338 ms 14528 KB Output is correct
20 Correct 318 ms 14736 KB Output is correct
21 Correct 300 ms 14740 KB Output is correct
22 Correct 309 ms 14536 KB Output is correct
23 Correct 319 ms 14532 KB Output is correct
24 Correct 323 ms 14624 KB Output is correct
25 Correct 205 ms 15300 KB Output is correct
26 Correct 175 ms 15328 KB Output is correct
27 Correct 322 ms 15116 KB Output is correct
28 Correct 317 ms 15008 KB Output is correct
29 Correct 344 ms 15100 KB Output is correct
30 Correct 308 ms 15128 KB Output is correct
31 Correct 348 ms 14972 KB Output is correct
32 Correct 215 ms 14592 KB Output is correct
33 Correct 1 ms 8536 KB Output is correct