# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
228756 | Rakhmand | Fire (JOI20_ho_t5) | C++14 | 1094 ms | 7544 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// I feel still alive.
// Created by existence on 18/04/2003.
// Copyright © 2020 Rakhman. All rights reserved.
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <iterator>
#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define nl '\n'
const long long mxn = 1e6 + 10;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
typedef long long llong;
using namespace std;
void istxt(bool yes){
if(yes == 1){
freopen("balancing.in", "r", stdin);
freopen("balancing.out", "w", stdout);
}else{
freopen("/Users/rakhmanabdirashov/Desktop/folder/Programming/Road2Master/Road2Master/input.txt", "r", stdin);
}
}
int n, Q, b[mxn], l[mxn], mx[mxn];
llong ans[mxn];
struct query{
int t, l, r, ind;
}q[mxn];
bool cmp(query a, query b){
return a.t < b.t;
}
int main () {
ios;
//istxt(0);
cin >> n >> Q;
for(int i = 1; i <= n; i++){
cin >> b[i];
mx[i] = b[i];
l[i] = i;
}
for(int i = 1; i <= Q; i++){
cin >> q[i].t >> q[i].l >> q[i].r;
q[i].ind = i;
}
sort(q + 1, q + Q + 1, cmp);
for(int qq = 1; qq <= Q; qq++){
int last = q[qq].t - q[qq - 1].t;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= last; j++){
l[i]--;
if(l[i] <= 0) break;
mx[i] = max(mx[i], b[l[i]]);
}
}
llong sum = 0;
for(int i = q[qq].l; i <= q[qq].r; i++){
sum += mx[i];
}
ans[q[qq].ind] = sum;
}
for(int i = 1; i <= n; i++){
cout << ans[i] << nl;
}
return 0;
}
/*
5 5
9 3 2 6 5
1 1 3
2 1 5
3 2 5
4 3 3
5 3 5
10 10
3 1 4 1 5 9 2 6 5 3
1 1 6
2 8 10
4 2 7
8 3 3
6 1 10
3 2 8
5 1 9
7 4 5
9 7 9
10 10 10
10 10
3 1 4 1 5 9 2 6 5 3
1 6 6
2 8 8
4 2 2
8 3 3
6 1 1
3 4 4
5 5 5
7 10 10
9 8 8
10 7 7
10 10
3 1 4 1 5 9 2 6 5 3
7 1 6
7 8 10
7 2 7
7 3 3
7 1 10
7 2 8
7 1 9
7 4 5
7 7 9
7 10 10
20 20
2 1 2 2 1 1 1 1 2 2 2 1 2 1 1 2 1 2 1 1
1 1 14
2 3 18
4 10 15
8 2 17
9 20 20
4 8 19
7 2 20
11 1 5
13 2 8
20 1 20
2 12 15
7 1 14
12 7 18
14 2 17
9 19 20
12 12 12
6 2 15
11 2 15
19 12 17
4 1 20
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |