# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1169323 | SmuggingSpun | Fish 3 (JOI24_fish3) | C++20 | 62 ms | 6732 KiB |
#include<bits/stdc++.h>
#define taskname "A"
using namespace std;
typedef long long ll;
template<class T>void minimize(T& a, T b){
if(a > b){
a = b;
}
}
const int lim = 3e5 + 5;
const ll INF = 1e18;
int n, q;
ll d, c[lim];
namespace sub1{
void solve(){
for(int _ = 0; _ < q; _++){
int l, r;
cin >> l >> r;
ll mn = INF, ans = 0;
for(int i = r; i >= l; i--){
minimize(mn, c[i]);
if((c[i] - mn) % d != 0 && (mn -= d - (c[i] - mn) % d) < 0){
ans = -1;
break;
}
ans += (c[i] - mn) / d;
}
cout << ans << "\n";
}
}
}
namespace sub2{
void solve(){
vector<int>left(n + 1), f(n + 1);
left[0] = f[0] = 0;
for(int i = 1; i <= n; i++){
left[i] = (c[i] == 0 ? i : left[i - 1]);
f[i] = f[i - 1] + c[i];
}
for(int _ = 0; _ < q; _++){
int l, r;
cin >> l >> r;
if(left[r] <= l){
cout << "0\n";
continue;
}
if(d == 1){
cout << f[left[r]] - f[l - 1] << "\n";
}
else{
cout << (f[left[r]] - f[l - 1] == 0 ? 0 : -1) << "\n";
}
}
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
cin >> n >> d;
for(int i = 1; i <= n; i++){
cin >> c[i];
}
cin >> q;
if(max(n, q) <= 3000){
sub1::solve();
}
else if(*max_element(c + 1, c + n + 1) <= 1){
sub2::solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |