제출 #1111718

#제출 시각아이디문제언어결과실행 시간메모리
1111718zxciganFish 3 (JOI24_fish3)C++17
0 / 100
90 ms8680 KiB
#include <bits/stdc++.h> using namespace std; mt19937_64 rng(time(0)); using ll = long long; #define int long long const int N = 2e5 + 1; void solve() { int n, d; cin >> n >> d; vector<int> c(n + 1), pref (n + 1); for (int i = 1; i <= n; ++i) { cin >> c[i]; pref[i] = pref[i - 1] + c[i]; } int q; cin >> q; while (q--) { int l, r; cin >> l >> r; if (pref[r] - pref[l - 1] == r - l + 1) { cout << "0\n"; continue; } int L = l, R = r; while (L < R) { int mid = (R + L) >> 1; if (pref[r] - pref[mid - 1] == r - mid + 1) R = mid; else L = mid + 1; } int ans = 0; if (pref[r] - pref[L - 1] == r - L + 1) { ans = pref[r] - pref[l - 1] - (pref[r] - pref[L - 1]); } else { ans = pref[r] - pref[l - 1]; } if (ans) { if (d != 1) { cout << "-1\n"; return; } } cout << ans << '\n'; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // LOCAL int T = 1; while (T--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...