//#include "dango3.h"
#include <bits/stdc++.h>
using namespace std;
int logg[100001],sp[100001][17];
int get(int l,int r){
int sz = r-l+1;
int lo = logg[sz];
return max(sp[l][lo],sp[r-(1<<lo)+1][lo]);
}
signed main(){
//freopen("input.txt","r",stdin);
//freopen("outout.txt","w",stdout);
int n;
cin>>n;
long long arr[n+1],pref[n+1] = {0};
for(int i = 1;i<=n;i++){
cin>>arr[i];
sp[i][0] = arr[i];
pref[i] = arr[i]+pref[i-1];
}
logg[1] = 0;
for(int i = 2;i<=n;i++){
logg[i] = logg[i/2]+1;
}
for(int i = n;i>=1;i--){
for(int j = 1;j<17;j++){
if(i+(1<<j)-1<=n){
sp[i][j] = max(sp[i][j-1],sp[i+(1<<(j-1))][j-1]);
}
}
}
int q;cin>>q;
int ty,l,r;cin>>ty>>l>>r;
long long fin = 0;
for(int i = 1;i<=n;i++){
int cnt = 0;
long long l = i , r = i , sum = 0;
bool ss = 0;
while(cnt<=1){
sum = pref[r]-pref[l-1];
if(ss==0){
int L = 1 , R = l-1 , ans = l;
while(L<=R){
int mid = (L+R)/2;
if(get(mid,l-1)<=sum){
ans = mid;
R = mid-1;
}else L = mid+1;
}
if(l==ans){
cnt++;
}else{
l = ans;
cnt = 0;
}
}else{
int L = r+1 , R = n , ans = r;
while(L<=R){
int mid = (L+R)/2;
if(get(r+1,mid)<=sum){
ans = mid;
L = mid+1;
}else R = mid-1;
}
if(r==ans){
cnt++;
}else{
r = ans;
cnt = 0;
}
}
ss = !ss;
}
if(l==1&&r==n){
fin++;
}
}
cout<<fin<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
42 ms |
9556 KB |
Output is correct |
3 |
Correct |
47 ms |
9308 KB |
Output is correct |
4 |
Correct |
42 ms |
9552 KB |
Output is correct |
5 |
Correct |
37 ms |
9308 KB |
Output is correct |
6 |
Correct |
52 ms |
10232 KB |
Output is correct |
7 |
Correct |
76 ms |
8792 KB |
Output is correct |
8 |
Correct |
51 ms |
9040 KB |
Output is correct |
9 |
Correct |
75 ms |
9020 KB |
Output is correct |
10 |
Correct |
55 ms |
9020 KB |
Output is correct |
11 |
Correct |
39 ms |
8796 KB |
Output is correct |
12 |
Correct |
45 ms |
9020 KB |
Output is correct |
13 |
Correct |
46 ms |
8796 KB |
Output is correct |
14 |
Correct |
45 ms |
8784 KB |
Output is correct |
15 |
Correct |
43 ms |
8792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
42 ms |
9556 KB |
Output is correct |
3 |
Correct |
47 ms |
9308 KB |
Output is correct |
4 |
Correct |
42 ms |
9552 KB |
Output is correct |
5 |
Correct |
37 ms |
9308 KB |
Output is correct |
6 |
Correct |
52 ms |
10232 KB |
Output is correct |
7 |
Correct |
76 ms |
8792 KB |
Output is correct |
8 |
Correct |
51 ms |
9040 KB |
Output is correct |
9 |
Correct |
75 ms |
9020 KB |
Output is correct |
10 |
Correct |
55 ms |
9020 KB |
Output is correct |
11 |
Correct |
39 ms |
8796 KB |
Output is correct |
12 |
Correct |
45 ms |
9020 KB |
Output is correct |
13 |
Correct |
46 ms |
8796 KB |
Output is correct |
14 |
Correct |
45 ms |
8784 KB |
Output is correct |
15 |
Correct |
43 ms |
8792 KB |
Output is correct |
16 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
42 ms |
9556 KB |
Output is correct |
3 |
Correct |
47 ms |
9308 KB |
Output is correct |
4 |
Correct |
42 ms |
9552 KB |
Output is correct |
5 |
Correct |
37 ms |
9308 KB |
Output is correct |
6 |
Correct |
52 ms |
10232 KB |
Output is correct |
7 |
Correct |
76 ms |
8792 KB |
Output is correct |
8 |
Correct |
51 ms |
9040 KB |
Output is correct |
9 |
Correct |
75 ms |
9020 KB |
Output is correct |
10 |
Correct |
55 ms |
9020 KB |
Output is correct |
11 |
Correct |
39 ms |
8796 KB |
Output is correct |
12 |
Correct |
45 ms |
9020 KB |
Output is correct |
13 |
Correct |
46 ms |
8796 KB |
Output is correct |
14 |
Correct |
45 ms |
8784 KB |
Output is correct |
15 |
Correct |
43 ms |
8792 KB |
Output is correct |
16 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |