#include "bits/stdc++.h"
using namespace std;
#define int long long
#define ar array
const int N = 1e5 + 5;
const int inf = 1e9;
int a[N], is[N];
int st[N][20], pref[N];
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
pref[i] = pref[i-1] + a[i];
st[i][0] = pref[i-1] + a[i-1];
}
for(int j=1;j<20;j++){
for(int i=1;i+(1 << (j-1)) <=n;i++){
st[i][j] = max(st[i][j-1], st[i + (1 << (j-1))][j-1]);
}
}
auto get = [&](int l, int r){
int lg = __lg(r - l + 1);
return max(st[l][lg], st[r - (1 << lg) + 1][lg]);
};
int q; cin>>q;
int t, l, r; cin>>t>>l>>r;
for(int i=1;i<=n;i++){
int l = 1, r = i + 1;
while(l < r){
int m = (l + r) >> 1;
auto check = [&](int l){
return pref[i] - a[i+1] < pref[l-1];
};
if(check(m)) r = m;
else l = m + 1;
}
int pl = l;
r = i + 1;
while(l < r){
auto check = [&](int pr){
return pref[i] < get(pl, pr);
};
int m = (l + r) >> 1;
if(check(m)) r = m;
else l = m + 1;
}
is[l]++, is[i+1]--;
cout<<i<<" "<<l<<"\n";
}
for(int i=1;i<=n;i++) is[i] += is[i-1];
int res=0;
for(int i=1;i<=n;i++){
res += !is[i];
}
cout<<res<<"\n";
return 0;
}
/*
5
6 4 2 2 6
1
2 1 5
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |