이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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];
ll 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 ("c");
int num_Test = 1;
// cin >> num_Test;
while (num_Test--)
solution();
}
/*
10 3
558103292241 930416975101 878795845384 804480358330 767898782842 927334443478 767423599302 776338370164 666494289968 823066426292
5
6 7
4 9
1 5
1 5
8 9
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |