# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
817952 |
2023-08-09T21:22:46 Z |
AdamGS |
Dungeon 3 (JOI21_ho_t5) |
C++17 |
|
4000 ms |
9700 KB |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(),a.end()
const int LIM=2e5+7;
ll A[LIM], pos[LIM], B[LIM], mi[LIM], mil[LIM];
ll solve(int l, int r, ll u) {
for(int i=l; i<r; ++i) if(A[i]>u) return -1;
int pocz=l;
ll ans=0;
while(l<r) {
ll prawo=min(pos[mi[l]], pos[r]);
if(mil[l]<pocz || pos[l]-pos[mil[l]]>=u) {
ans+=B[l]*min(prawo-pos[l], u);
} else if(prawo-pos[mil[l]]>u) {
ans+=B[l]*min(prawo-pos[mil[l]]-u, u);
}
++l;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, m;
cin >> n >> m;
rep(i, n) {
cin >> A[i];
pos[i+1]=pos[i]+A[i];
}
rep(i, n) cin >> B[i];
A[n]=-1;
stack<pair<ll,ll>>S;
S.push({-1, n});
for(int i=n-1; i>=0; --i) {
while(S.top().st>B[i]) S.pop();
mi[i]=S.top().nd;
S.push({B[i], i});
}
while(!S.empty()) S.pop();
S.push({-1, -1});
rep(i, n) {
while(S.top().st>=B[i]) S.pop();
mil[i]=S.top().nd;
S.push({B[i], i});
}
while(m--) {
ll l, r, u;
cin >> l >> r >> u; --l; --r;
cout << solve(l, r, u) << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1798 ms |
4700 KB |
Output is correct |
2 |
Incorrect |
3426 ms |
4668 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4040 ms |
9700 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |