Submission #1012843

# Submission time Handle Problem Language Result Execution time Memory
1012843 2024-07-02T16:59:06 Z underwaterkillerwhale Fish 3 (JOI24_fish3) C++17
0 / 100
2000 ms 5716 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  = 3e5 + 7;
const int Mod = 998244353;
const int szBL = 916;
const ll INF = 1e9;
const int BASE = 137;

int n, Q;
ll D;
ll a[N], b[N];

void solution() {
    cin >> n >> D;
    rep (i, 1, n)
        cin >> a[i];
    cin >> Q;
    rep (q, 1, Q) {
        int L, R;
        cin >> L >> R;
        rep (i, L, R) b[i] = a[i];
        int res = 0;
        reb (i, R, L + 1) {
            if (b[i] >= b[i - 1]) continue;
            else {
                res += ceil(1.0 * (b[i - 1] - b[i]) / D);
                b[i - 1] = b[i - 1] - D * ceil(1.0 * (b[i - 1] - b[i]) / D);
            }
        }
//        rep (i, L, R) cout << b[i] <<" ";
        if (b[L] >= 0)
        cout << res <<"\n";
        else cout << -1 <<"\n";
    }
}


#define file(name) freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);
int main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    file ("WATERMOV");
    int num_Test = 1;
//    cin >> num_Test;
    while (num_Test--)
        solution();
}
/*
6 6 4
2 2 3 6
2 2 6 3
2 4 4 5
4 2 6 4
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Incorrect 0 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2072 ms 5432 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2032 ms 5716 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2044 ms 5068 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Incorrect 0 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -