Submission #1029952

# Submission time Handle Problem Language Result Execution time Memory
1029952 2024-07-21T14:29:00 Z underwaterkillerwhale Worst Reporter 3 (JOI18_worst_reporter3) C++17
100 / 100
386 ms 45176 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 = 1e6 + 7;
const int Mod = 1e9 + 7;
const int szBL = 320;
const ll INF = 1e9 + 160907;
const int BASE = 1337;

struct Query {
    ll T, L, R, id;
};
int n, Q, m;
ll D[N];
ll dp[N];
ll 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<ll> 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]));
//        cout << i <<":" <<dp[i] <<" "<<D[i] <<"\n";
        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];
        ll 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
*/
# Verdict Execution time Memory Grader output
1 Correct 192 ms 42436 KB Output is correct
2 Correct 186 ms 42360 KB Output is correct
3 Correct 211 ms 42492 KB Output is correct
4 Correct 165 ms 42428 KB Output is correct
5 Correct 167 ms 42600 KB Output is correct
6 Correct 174 ms 42432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 552 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 192 ms 42436 KB Output is correct
2 Correct 186 ms 42360 KB Output is correct
3 Correct 211 ms 42492 KB Output is correct
4 Correct 165 ms 42428 KB Output is correct
5 Correct 167 ms 42600 KB Output is correct
6 Correct 174 ms 42432 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 552 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 484 KB Output is correct
13 Correct 197 ms 40904 KB Output is correct
14 Correct 236 ms 41676 KB Output is correct
15 Correct 197 ms 40240 KB Output is correct
16 Correct 196 ms 40796 KB Output is correct
17 Correct 275 ms 45068 KB Output is correct
18 Correct 327 ms 44912 KB Output is correct
19 Correct 358 ms 45156 KB Output is correct
20 Correct 279 ms 45016 KB Output is correct
21 Correct 340 ms 45012 KB Output is correct
22 Correct 334 ms 45176 KB Output is correct
23 Correct 371 ms 44992 KB Output is correct
24 Correct 338 ms 44992 KB Output is correct
25 Correct 175 ms 42392 KB Output is correct
26 Correct 209 ms 42468 KB Output is correct
27 Correct 326 ms 44604 KB Output is correct
28 Correct 342 ms 45040 KB Output is correct
29 Correct 342 ms 44480 KB Output is correct
30 Correct 386 ms 44680 KB Output is correct
31 Correct 369 ms 44728 KB Output is correct
32 Correct 202 ms 41152 KB Output is correct
33 Correct 1 ms 348 KB Output is correct