#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}
struct Seg {
ll siz = 1;
vector<ll> sums;
void init(int n){
while(siz < n)siz*=2;
sums.assign(siz * 2, 0LL);
}
void build(vector<int>& arr , int x , int lx , int rx){
if(rx-lx==1){
if(lx < (int)arr.size()){
sums[x] = arr[lx];
}
return;
}
int m = (lx + rx) / 2;
build(arr , 2 * x + 1 , lx , m);
build(arr, 2 * x + 2 , m , rx);
sums[x] = max(sums[2 * x + 1] , sums[2 * x + 2]);
}
void build(vector<int>& arr){
build(arr , 0 , 0 , siz);
}
void set(int i , int v , int x , int lx , int rx){
if(rx - lx ==1){
sums[x] = v;
return;
}
int m = (lx + rx) / 2;
if(i < m){
set(i , v , 2 * x + 1 , lx , m);
}
else {
set(i , v , 2 * x + 2 , m , rx);
}
sums[x]=max(sums[2 * x + 1] , sums[2 * x + 2]);
}
void set(int x , int y){
set(x ,y , 0 , 0 , siz);
}
ll sum(int l , int r , int x , int lx , int rx){
if(lx >= l && rx <= r){
return sums[x];
}
if(lx >= r || rx <= l)return 0;
int m = (lx + rx) / 2;
return max(sum(l , r , 2 * x + 1 , lx , m) , sum(l , r , 2 * x + 2 , m , rx));
}
ll sum(int l , int r){
return sum(l , r , 0 , 0 , siz);
}
};
void solve(){
int n,q;
cin >> n >> q;
vector<int> arr(n);
for(int i = 0; i < n; i++)cin >> arr[i];
Seg st;
st.init(n + 5);
st.build(arr);
while(q--){
int t , l , r;
cin >> t >> l >> r;
l--;
r--;
ll ans = 0;
for(int i = l; i <= r; i++){
int x = i - t;
x = max(x , 0);
ans += st.sum(x , i + 1);
}
cout << ans << '\n';
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//int t;cin >> t;while(t--)
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
312 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
2 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
3 ms |
204 KB |
Output is correct |
26 |
Correct |
2 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
2 ms |
316 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
2 ms |
204 KB |
Output is correct |
32 |
Correct |
2 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Execution timed out |
1088 ms |
7212 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
152 ms |
12692 KB |
Output is correct |
3 |
Correct |
140 ms |
12492 KB |
Output is correct |
4 |
Correct |
139 ms |
12772 KB |
Output is correct |
5 |
Correct |
140 ms |
12528 KB |
Output is correct |
6 |
Correct |
149 ms |
12660 KB |
Output is correct |
7 |
Correct |
140 ms |
12592 KB |
Output is correct |
8 |
Correct |
140 ms |
12740 KB |
Output is correct |
9 |
Correct |
140 ms |
12672 KB |
Output is correct |
10 |
Correct |
138 ms |
12544 KB |
Output is correct |
11 |
Correct |
147 ms |
12740 KB |
Output is correct |
12 |
Correct |
142 ms |
12652 KB |
Output is correct |
13 |
Correct |
147 ms |
12740 KB |
Output is correct |
14 |
Correct |
135 ms |
12612 KB |
Output is correct |
15 |
Correct |
155 ms |
12724 KB |
Output is correct |
16 |
Correct |
169 ms |
12496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1087 ms |
5708 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
312 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
2 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
3 ms |
204 KB |
Output is correct |
26 |
Correct |
2 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
2 ms |
316 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
2 ms |
204 KB |
Output is correct |
32 |
Correct |
2 ms |
204 KB |
Output is correct |
33 |
Execution timed out |
1088 ms |
7212 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |