# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
250862 |
2020-07-19T10:14:14 Z |
combi1k1 |
Fire (JOI20_ho_t5) |
C++14 |
|
59 ms |
26360 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define pb emplace_back
#define X first
#define Y second
const int N = 2e5 + 5;
typedef pair<ll,ll> pll;
struct BIT {
pll T[N + N];
int upd(int p,pll d) {
for(p += N ; p < N + N ; p += p & -p)
T[p].X += d.X,
T[p].Y += d.Y;
return 1;
}
ll get(int p,int x) {
ll s = 0;
ll c = 0;
for(p += N + 1 ; p > 0 ; p -= p & -p)
s += T[p].X,
c += T[p].Y;
return s * x - c;
}
} pref;
BIT suff;
int a[N];
int l[N];
int r[N];
vector<tuple<int,int,int> > Upd[N];
vector<tuple<int,int,int> > Que[N];
void Add(int l,int r,int v) {
if (l > r) return;
int k = r - l + 1;
Upd[0].pb(l,r, v);
Upd[k].pb(l,r,-v);
}
ll ask(int T,int r) {
ll ans = 0;
ans += suff.get(r,r); r -= T;
ans += pref.get(r,r);
return ans;
}
ll ans[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
int q; cin >> q;
for(int i = 1 ; i <= n ; ++i)
cin >> a[i];
stack<int> st;
for(int i = 1 ; i <= n ; ++i) {
while (st.size() && a[st.top()] <= a[i])
st.pop();
if (st.size()) l[i] = st.top() + 1;
else l[i] = -n;
st.push(i);
}
while (st.size()) st.pop();
for(int i = n ; i >= 1 ; --i) {
while (st.size() && a[st.top()] < a[i])
st.pop();
if (st.size()) r[i] = st.top() - 1;
else r[i] = n;
st.push(i);
}
for(int i = 1 ; i <= n ; ++i) {
Add(l[i] ,r[i] , a[i]);
Add(l[i] ,i - 1,-a[i]);
Add(i + 1,r[i] ,-a[i]);
}
for(int i = 0 ; i < q ; ++i) {
int t; cin >> t;
int l; cin >> l;
int r; cin >> r;
Que[t].pb(l,r,i);
}
for(int t = 0 ; t <= n ; ++t) {
for(auto it : Upd[t]) {
int l, r, v;
tie(l, r, v) = it; ++r;
pref.upd(l,pll( v, 1ll * v * (l - 1)));
suff.upd(r,pll(-v,-1ll * v * (r - 1)));
}
for(auto it : Que[t]) {
int l, r, i;
tie(l, r, i) = it;
ans[i] += ask(t,r);
ans[i] -= ask(t,l - 1);
}
}
for(int i = 0 ; i < q ; ++i)
cout << ans[i] << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9856 KB |
Output is correct |
2 |
Correct |
6 ms |
9856 KB |
Output is correct |
3 |
Correct |
6 ms |
9856 KB |
Output is correct |
4 |
Correct |
6 ms |
9856 KB |
Output is correct |
5 |
Correct |
6 ms |
9856 KB |
Output is correct |
6 |
Correct |
6 ms |
9856 KB |
Output is correct |
7 |
Correct |
6 ms |
9856 KB |
Output is correct |
8 |
Correct |
6 ms |
9856 KB |
Output is correct |
9 |
Correct |
6 ms |
9856 KB |
Output is correct |
10 |
Correct |
6 ms |
9856 KB |
Output is correct |
11 |
Correct |
6 ms |
9856 KB |
Output is correct |
12 |
Correct |
6 ms |
9856 KB |
Output is correct |
13 |
Correct |
6 ms |
9856 KB |
Output is correct |
14 |
Correct |
8 ms |
9856 KB |
Output is correct |
15 |
Correct |
6 ms |
9856 KB |
Output is correct |
16 |
Correct |
7 ms |
9856 KB |
Output is correct |
17 |
Correct |
6 ms |
9856 KB |
Output is correct |
18 |
Correct |
6 ms |
9856 KB |
Output is correct |
19 |
Correct |
7 ms |
9856 KB |
Output is correct |
20 |
Correct |
9 ms |
9856 KB |
Output is correct |
21 |
Correct |
6 ms |
9856 KB |
Output is correct |
22 |
Correct |
7 ms |
9856 KB |
Output is correct |
23 |
Correct |
7 ms |
9856 KB |
Output is correct |
24 |
Correct |
6 ms |
9856 KB |
Output is correct |
25 |
Correct |
8 ms |
9856 KB |
Output is correct |
26 |
Correct |
6 ms |
9856 KB |
Output is correct |
27 |
Correct |
6 ms |
9856 KB |
Output is correct |
28 |
Correct |
7 ms |
9856 KB |
Output is correct |
29 |
Correct |
6 ms |
9856 KB |
Output is correct |
30 |
Correct |
6 ms |
9856 KB |
Output is correct |
31 |
Correct |
6 ms |
9856 KB |
Output is correct |
32 |
Correct |
6 ms |
9856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9856 KB |
Output is correct |
2 |
Runtime error |
56 ms |
24884 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9856 KB |
Output is correct |
2 |
Runtime error |
54 ms |
25068 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
47 ms |
26360 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9856 KB |
Output is correct |
2 |
Correct |
6 ms |
9856 KB |
Output is correct |
3 |
Correct |
6 ms |
9856 KB |
Output is correct |
4 |
Correct |
6 ms |
9856 KB |
Output is correct |
5 |
Correct |
6 ms |
9856 KB |
Output is correct |
6 |
Correct |
6 ms |
9856 KB |
Output is correct |
7 |
Correct |
6 ms |
9856 KB |
Output is correct |
8 |
Correct |
6 ms |
9856 KB |
Output is correct |
9 |
Correct |
6 ms |
9856 KB |
Output is correct |
10 |
Correct |
6 ms |
9856 KB |
Output is correct |
11 |
Correct |
6 ms |
9856 KB |
Output is correct |
12 |
Correct |
6 ms |
9856 KB |
Output is correct |
13 |
Correct |
6 ms |
9856 KB |
Output is correct |
14 |
Correct |
8 ms |
9856 KB |
Output is correct |
15 |
Correct |
6 ms |
9856 KB |
Output is correct |
16 |
Correct |
7 ms |
9856 KB |
Output is correct |
17 |
Correct |
6 ms |
9856 KB |
Output is correct |
18 |
Correct |
6 ms |
9856 KB |
Output is correct |
19 |
Correct |
7 ms |
9856 KB |
Output is correct |
20 |
Correct |
9 ms |
9856 KB |
Output is correct |
21 |
Correct |
6 ms |
9856 KB |
Output is correct |
22 |
Correct |
7 ms |
9856 KB |
Output is correct |
23 |
Correct |
7 ms |
9856 KB |
Output is correct |
24 |
Correct |
6 ms |
9856 KB |
Output is correct |
25 |
Correct |
8 ms |
9856 KB |
Output is correct |
26 |
Correct |
6 ms |
9856 KB |
Output is correct |
27 |
Correct |
6 ms |
9856 KB |
Output is correct |
28 |
Correct |
7 ms |
9856 KB |
Output is correct |
29 |
Correct |
6 ms |
9856 KB |
Output is correct |
30 |
Correct |
6 ms |
9856 KB |
Output is correct |
31 |
Correct |
6 ms |
9856 KB |
Output is correct |
32 |
Correct |
6 ms |
9856 KB |
Output is correct |
33 |
Runtime error |
59 ms |
25464 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
34 |
Halted |
0 ms |
0 KB |
- |