# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
371314 |
2021-02-26T12:54:49 Z |
oolimry |
Dungeon 3 (JOI21_ho_t5) |
C++17 |
|
754 ms |
46192 KB |
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int) x.size())
#define show(x) cerr << #x << " is " << x << endl;
typedef long long lint;
typedef pair<lint, lint> ii;
const lint inf = 1e16;
const int N = 200015;
int n, Q;
lint X[N];
lint B[N];
lint R[N];
lint ans[N];
struct query{ lint U, id, mul; };
vector<query> queries[N];
vector<lint> dis;
int get(lint i){ return upper_bound(all(dis), i) - dis.begin(); }
struct seg{
lint tree[2*N];
lint query(int i){
lint res = 0;
for(i += N;i > 0;i >>= 1) res += tree[i];
return res;
}
void update(int l, int r, lint x){
for(l += N, r += N+1;l < r;l >>= 1, r >>= 1){
if(l&1) tree[l++] += x;
if(r&1) tree[--r] += x;
}
}
} m, c;
struct segmax{
lint tree[2*N];
lint query(int l, int r){
lint res = -inf;
for(l += N, r += N+1;l < r;l >>= 1, r >>= 1){
if(l&1) res = max(res, tree[l++]);
if(r&1) res = max(res, tree[--r]);
}
return res;
}
void update(int i, lint x){
for(i += N;i > 0;i >>= 1) tree[i] = max(tree[i], x);
}
} finddie;
struct segmin{
ii tree[2*N];
ii query(int l, int r){
ii res = ii(inf,inf);
for(l += N, r += N+1;l < r;l >>= 1, r >>= 1){
if(l&1) res = min(res, tree[l++]);
if(r&1) res = min(res, tree[--r]);
}
return res;
}
void update(int i, ii x){
for(i += N;i > 0;i >>= 1) tree[i] = min(tree[i], x);
}
} getmin;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> Q;
for(int i = 2;i <= n+1;i++) cin >> X[i];
for(int i = 1;i <= n;i++) cin >> B[i];
fill(m.tree,m.tree + N*2,0); fill(c.tree,c.tree + N*2,0);
fill(getmin.tree,getmin.tree + 2*N, ii(inf,inf));
for(int i = 2;i <= n+1;i++) finddie.update(i-1, X[i]);
for(int i = 1;i <= n;i++) getmin.update(i, ii(B[i],i));
for(int i = 2;i <= n+1;i++) X[i] += X[i-1];
for(int q = 1;q <= Q;q++){
int s, t, u; cin >> s >> t >> u;
if(finddie.query(s,t-1) > u) ans[q] = -1;
else{
queries[s].push_back({u,q,1});
int findpos = lower_bound(X+1, X+n+1, X[t] - u) - X;
lint tmiddle = getmin.query(max(s,findpos),t-1).second;
queries[tmiddle].push_back({u,q,-1});
ans[q] += (X[t]-X[tmiddle]) * B[tmiddle];
dis.push_back(u);
}
}
dis.push_back(inf);
sort(all(dis));
dis.erase(unique(all(dis)), dis.end());
stack<int> st;
B[n+1] = -inf; st.push(n+1);
lint maxdis = 0;
for(int s = n;s >= 1;s--){
maxdis = max(maxdis, X[s+1]-X[s]);
while(B[st.top()] >= B[s]){
///do something about st.top()
int i = st.top();
lint d1 = get(X[i] - X[s]);
lint d2 = get(X[R[i]] - X[s]);
m.update(d1+1, d2, -B[i]);
c.update(d1+1,d2, (X[i]-X[s]) * B[i]);
c.update(d2+1,N-1, (X[R[i]]-X[i]) * -B[i]);
st.pop();
}
///add the min(Xi+U, Ri)
int r = st.top();
R[s] = r;
lint D = get(X[r] - X[s]);
m.update(1, D, B[s]);
c.update(D+1, N-1, (X[r]-X[s]) * B[s]);
st.push(s);
for(query &q : queries[s]){
ans[q.id] += q.mul * (m.query(get(q.U)) * q.U + c.query(get(q.U)));
}
}
for(int q = 1;q <= Q;q++) cout << ans[q] << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
18028 KB |
Output is correct |
2 |
Correct |
19 ms |
18028 KB |
Output is correct |
3 |
Correct |
15 ms |
18028 KB |
Output is correct |
4 |
Correct |
16 ms |
18028 KB |
Output is correct |
5 |
Correct |
16 ms |
18028 KB |
Output is correct |
6 |
Correct |
15 ms |
18028 KB |
Output is correct |
7 |
Correct |
16 ms |
18028 KB |
Output is correct |
8 |
Correct |
16 ms |
18028 KB |
Output is correct |
9 |
Correct |
15 ms |
18028 KB |
Output is correct |
10 |
Correct |
18 ms |
18028 KB |
Output is correct |
11 |
Correct |
16 ms |
18156 KB |
Output is correct |
12 |
Correct |
15 ms |
18032 KB |
Output is correct |
13 |
Correct |
16 ms |
18028 KB |
Output is correct |
14 |
Correct |
16 ms |
18028 KB |
Output is correct |
15 |
Correct |
16 ms |
18028 KB |
Output is correct |
16 |
Correct |
16 ms |
18028 KB |
Output is correct |
17 |
Correct |
15 ms |
18028 KB |
Output is correct |
18 |
Correct |
15 ms |
18028 KB |
Output is correct |
19 |
Correct |
18 ms |
18028 KB |
Output is correct |
20 |
Correct |
15 ms |
18028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
24764 KB |
Output is correct |
2 |
Correct |
92 ms |
24404 KB |
Output is correct |
3 |
Correct |
93 ms |
24548 KB |
Output is correct |
4 |
Correct |
92 ms |
24676 KB |
Output is correct |
5 |
Correct |
95 ms |
24420 KB |
Output is correct |
6 |
Correct |
453 ms |
45924 KB |
Output is correct |
7 |
Correct |
449 ms |
44768 KB |
Output is correct |
8 |
Correct |
479 ms |
45192 KB |
Output is correct |
9 |
Correct |
485 ms |
46192 KB |
Output is correct |
10 |
Correct |
489 ms |
44636 KB |
Output is correct |
11 |
Correct |
490 ms |
44528 KB |
Output is correct |
12 |
Correct |
505 ms |
45712 KB |
Output is correct |
13 |
Correct |
430 ms |
42844 KB |
Output is correct |
14 |
Correct |
442 ms |
42108 KB |
Output is correct |
15 |
Correct |
226 ms |
40044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
626 ms |
41424 KB |
Output is correct |
2 |
Correct |
478 ms |
42716 KB |
Output is correct |
3 |
Correct |
488 ms |
42052 KB |
Output is correct |
4 |
Correct |
611 ms |
42144 KB |
Output is correct |
5 |
Correct |
470 ms |
41744 KB |
Output is correct |
6 |
Correct |
532 ms |
41484 KB |
Output is correct |
7 |
Correct |
463 ms |
38428 KB |
Output is correct |
8 |
Correct |
412 ms |
39896 KB |
Output is correct |
9 |
Correct |
425 ms |
39440 KB |
Output is correct |
10 |
Correct |
256 ms |
43012 KB |
Output is correct |
11 |
Correct |
380 ms |
38596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
18028 KB |
Output is correct |
2 |
Correct |
19 ms |
18028 KB |
Output is correct |
3 |
Correct |
15 ms |
18028 KB |
Output is correct |
4 |
Correct |
16 ms |
18028 KB |
Output is correct |
5 |
Correct |
16 ms |
18028 KB |
Output is correct |
6 |
Correct |
15 ms |
18028 KB |
Output is correct |
7 |
Correct |
16 ms |
18028 KB |
Output is correct |
8 |
Correct |
16 ms |
18028 KB |
Output is correct |
9 |
Correct |
15 ms |
18028 KB |
Output is correct |
10 |
Correct |
18 ms |
18028 KB |
Output is correct |
11 |
Correct |
16 ms |
18156 KB |
Output is correct |
12 |
Correct |
15 ms |
18032 KB |
Output is correct |
13 |
Correct |
16 ms |
18028 KB |
Output is correct |
14 |
Correct |
16 ms |
18028 KB |
Output is correct |
15 |
Correct |
16 ms |
18028 KB |
Output is correct |
16 |
Correct |
16 ms |
18028 KB |
Output is correct |
17 |
Correct |
15 ms |
18028 KB |
Output is correct |
18 |
Correct |
15 ms |
18028 KB |
Output is correct |
19 |
Correct |
18 ms |
18028 KB |
Output is correct |
20 |
Correct |
15 ms |
18028 KB |
Output is correct |
21 |
Correct |
98 ms |
24764 KB |
Output is correct |
22 |
Correct |
92 ms |
24404 KB |
Output is correct |
23 |
Correct |
93 ms |
24548 KB |
Output is correct |
24 |
Correct |
92 ms |
24676 KB |
Output is correct |
25 |
Correct |
95 ms |
24420 KB |
Output is correct |
26 |
Correct |
453 ms |
45924 KB |
Output is correct |
27 |
Correct |
449 ms |
44768 KB |
Output is correct |
28 |
Correct |
479 ms |
45192 KB |
Output is correct |
29 |
Correct |
485 ms |
46192 KB |
Output is correct |
30 |
Correct |
489 ms |
44636 KB |
Output is correct |
31 |
Correct |
490 ms |
44528 KB |
Output is correct |
32 |
Correct |
505 ms |
45712 KB |
Output is correct |
33 |
Correct |
430 ms |
42844 KB |
Output is correct |
34 |
Correct |
442 ms |
42108 KB |
Output is correct |
35 |
Correct |
226 ms |
40044 KB |
Output is correct |
36 |
Correct |
626 ms |
41424 KB |
Output is correct |
37 |
Correct |
478 ms |
42716 KB |
Output is correct |
38 |
Correct |
488 ms |
42052 KB |
Output is correct |
39 |
Correct |
611 ms |
42144 KB |
Output is correct |
40 |
Correct |
470 ms |
41744 KB |
Output is correct |
41 |
Correct |
532 ms |
41484 KB |
Output is correct |
42 |
Correct |
463 ms |
38428 KB |
Output is correct |
43 |
Correct |
412 ms |
39896 KB |
Output is correct |
44 |
Correct |
425 ms |
39440 KB |
Output is correct |
45 |
Correct |
256 ms |
43012 KB |
Output is correct |
46 |
Correct |
380 ms |
38596 KB |
Output is correct |
47 |
Correct |
740 ms |
42740 KB |
Output is correct |
48 |
Correct |
653 ms |
43348 KB |
Output is correct |
49 |
Correct |
617 ms |
44252 KB |
Output is correct |
50 |
Correct |
754 ms |
43868 KB |
Output is correct |
51 |
Correct |
661 ms |
44892 KB |
Output is correct |
52 |
Correct |
699 ms |
44256 KB |
Output is correct |
53 |
Correct |
625 ms |
40176 KB |
Output is correct |
54 |
Correct |
580 ms |
40284 KB |
Output is correct |
55 |
Correct |
549 ms |
41076 KB |
Output is correct |
56 |
Correct |
269 ms |
42984 KB |
Output is correct |
57 |
Correct |
527 ms |
39960 KB |
Output is correct |