제출 #1010708

#제출 시각아이디문제언어결과실행 시간메모리
1010708mychecksedadFish 3 (JOI24_fish3)C++17
9 / 100
2084 ms75240 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; #define ll long long int #define MOD (1000000000+7) #define MOD1 (998244353) #define pb push_back #define all(x) x.begin(), x.end() #define en cout << '\n' const int N = 3e5+100, M = 1e5+10, K = 20, MX = 30; int n, q; ll D, C[N], B[N], suf[N], arr[N], rmq[N][K], pref[N], S[N]; array<ll, 2> L[N]; ll get(int l, int r){ int k= log2(r-l+1); return min(rmq[l][k], rmq[r-(1<<k)+1][k]); } void solve(){ cin >> n >> D; for(int i = 1; i <= n; ++i) cin >> C[i]; B[1] = C[1] % D; for(int i = 2; i <= n; ++i){ if(C[i] % D >= C[i-1] % D){ B[i] = B[i-1] + (C[i]%D)-(C[i-1]%D); }else{ B[i] = B[i-1] + D + (C[i]%D)-(C[i-1]%D); } } for(int i = 1; i <= n; ++i) arr[i] = rmq[i][0] = C[i] - B[i]; for(int j = 1; j < K ;++j){ for(int i = 1; i + (1<<j) <= n+1; ++i){ rmq[i][j] = min(rmq[i][j - 1], rmq[i+(1<<(j-1))][j-1]); } } pref[0] = 0; S[0] = 0; C[0] = arr[0] = 0; for(int i = 1; i <= n; ++i) pref[i] = pref[i - 1] + B[i]; for(int i = 1; i <= n; ++i) S[i] = S[i - 1] + C[i]; deque<pair<ll, int>> Q; L[1] = {0, arr[1]}; Q.pb({arr[1], 1}); for(int i = 2; i <= n; ++i){ while(!Q.empty() && Q.back().first > arr[i]) Q.pop_back(); if(Q.empty()) L[i] = {0, arr[i]}; else L[i] = {Q.back().second, arr[i]}; Q.pb({arr[i], i}); } // for(int i = 1; i <= n; ++i) cout << B[i] << ' ';en; // for(int i = 1; i <= n; ++i) cout << arr[i] << ' ';en; // for(int i = 1; i <= n; ++i) cout << L[i][0] << ' ';en; cin >> q; for(int i = 1; i <= q; ++i){ int l, r; cin >> l >> r; ll ans = 0; ll mn = get(l, r); ll R = B[l] - (C[l]%D); if(mn + R < 0){ cout << -1 << '\n'; continue; } // cout << R << ' '; ans = ( S[r] - S[l-1] - (pref[r] - pref[l-1] - (r-l+1)*R)); // cout << S[r] - S[l-1] << ' ' << pref[r]-pref[l-1] << '\n'; int p = r; while(p > l-1){ if(L[p][0] < l){ ans -= (arr[p] + R) * (p - l + 1); }else{ ans -= (arr[p] + R) * (p - L[p][0]); } p = L[p][0]; } if(ans % D != 0) cout << -1 << '\n'; else cout << ans / D << '\n'; } } int main(){ cin.tie(0); ios::sync_with_stdio(0); int tt = 1, aa; // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); while(tt--){ solve(); } cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n"; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:87:15: warning: unused variable 'aa' [-Wunused-variable]
   87 |   int tt = 1, aa;
      |               ^~
#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...