#include "bits/stdc++.h"
#define MAXN 500009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int dp[MAXN],arr[MAXN],n,ok,tmp;
ll par[MAXN];
set<int>one,zero;
int get(int i){
return lower_bound(par+i+1,par+n+1,2*par[i]-par[dp[i]])-par;
}
int main(){
// freopen("file.in", "r", stdin);
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",arr+i);
par[i]=par[i-1]+arr[i];
}
for(int i=1;i<=n;i++)
one.insert(i);
stack<int>add,rem,far;
for(int j=2;j<=n;j++){
ok=0;
__typeof((one).begin())a=one.end();
while(a!=one.begin()){a--;
if(*a<j-1)
break;
tmp=get(*a);
__typeof((zero).begin())b=zero.end();
while(b!=zero.begin()){b--;
if(*b<tmp)
break;
dp[*b]=*a;ok=1;
add.push(*b);
far.push(*b);
}
zero.insert(*a);
while(!far.empty())
zero.erase(far.top()),far.pop();
rem.push(*a);
}
while(!rem.empty())
one.erase(rem.top()),rem.pop();
while(!add.empty())
one.insert(add.top()),add.pop();
if(!ok){
printf("%d\n",j-1);
return 0;
}
}printf("%d\n",n);
return 0;
}
Compilation message
segments.cpp: In function 'int main()':
segments.cpp:58:6: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
58 | while(!add.empty())
| ^~~~~
segments.cpp:60:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
60 | if(!ok){
| ^~
segments.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
28 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
segments.cpp:30:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
30 | scanf("%d",arr+i);
| ~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
8 ms |
364 KB |
Output is correct |
19 |
Correct |
32 ms |
364 KB |
Output is correct |
20 |
Correct |
35 ms |
436 KB |
Output is correct |
21 |
Correct |
5 ms |
364 KB |
Output is correct |
22 |
Correct |
4 ms |
364 KB |
Output is correct |
23 |
Correct |
3 ms |
364 KB |
Output is correct |
24 |
Correct |
7 ms |
364 KB |
Output is correct |
25 |
Correct |
5 ms |
364 KB |
Output is correct |
26 |
Correct |
33 ms |
364 KB |
Output is correct |
27 |
Correct |
23 ms |
364 KB |
Output is correct |
28 |
Correct |
10 ms |
364 KB |
Output is correct |
29 |
Correct |
34 ms |
364 KB |
Output is correct |
30 |
Correct |
35 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
8 ms |
364 KB |
Output is correct |
19 |
Correct |
32 ms |
364 KB |
Output is correct |
20 |
Correct |
35 ms |
436 KB |
Output is correct |
21 |
Correct |
5 ms |
364 KB |
Output is correct |
22 |
Correct |
4 ms |
364 KB |
Output is correct |
23 |
Correct |
3 ms |
364 KB |
Output is correct |
24 |
Correct |
7 ms |
364 KB |
Output is correct |
25 |
Correct |
5 ms |
364 KB |
Output is correct |
26 |
Correct |
33 ms |
364 KB |
Output is correct |
27 |
Correct |
23 ms |
364 KB |
Output is correct |
28 |
Correct |
10 ms |
364 KB |
Output is correct |
29 |
Correct |
34 ms |
364 KB |
Output is correct |
30 |
Correct |
35 ms |
364 KB |
Output is correct |
31 |
Correct |
2 ms |
620 KB |
Output is correct |
32 |
Correct |
7 ms |
620 KB |
Output is correct |
33 |
Correct |
112 ms |
620 KB |
Output is correct |
34 |
Correct |
1175 ms |
748 KB |
Output is correct |
35 |
Correct |
1343 ms |
748 KB |
Output is correct |
36 |
Correct |
77 ms |
620 KB |
Output is correct |
37 |
Correct |
57 ms |
620 KB |
Output is correct |
38 |
Correct |
43 ms |
492 KB |
Output is correct |
39 |
Correct |
80 ms |
620 KB |
Output is correct |
40 |
Correct |
81 ms |
620 KB |
Output is correct |
41 |
Correct |
1319 ms |
748 KB |
Output is correct |
42 |
Correct |
1222 ms |
748 KB |
Output is correct |
43 |
Correct |
359 ms |
748 KB |
Output is correct |
44 |
Correct |
1346 ms |
660 KB |
Output is correct |
45 |
Correct |
1356 ms |
748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
8 ms |
364 KB |
Output is correct |
19 |
Correct |
32 ms |
364 KB |
Output is correct |
20 |
Correct |
35 ms |
436 KB |
Output is correct |
21 |
Correct |
5 ms |
364 KB |
Output is correct |
22 |
Correct |
4 ms |
364 KB |
Output is correct |
23 |
Correct |
3 ms |
364 KB |
Output is correct |
24 |
Correct |
7 ms |
364 KB |
Output is correct |
25 |
Correct |
5 ms |
364 KB |
Output is correct |
26 |
Correct |
33 ms |
364 KB |
Output is correct |
27 |
Correct |
23 ms |
364 KB |
Output is correct |
28 |
Correct |
10 ms |
364 KB |
Output is correct |
29 |
Correct |
34 ms |
364 KB |
Output is correct |
30 |
Correct |
35 ms |
364 KB |
Output is correct |
31 |
Correct |
2 ms |
620 KB |
Output is correct |
32 |
Correct |
7 ms |
620 KB |
Output is correct |
33 |
Correct |
112 ms |
620 KB |
Output is correct |
34 |
Correct |
1175 ms |
748 KB |
Output is correct |
35 |
Correct |
1343 ms |
748 KB |
Output is correct |
36 |
Correct |
77 ms |
620 KB |
Output is correct |
37 |
Correct |
57 ms |
620 KB |
Output is correct |
38 |
Correct |
43 ms |
492 KB |
Output is correct |
39 |
Correct |
80 ms |
620 KB |
Output is correct |
40 |
Correct |
81 ms |
620 KB |
Output is correct |
41 |
Correct |
1319 ms |
748 KB |
Output is correct |
42 |
Correct |
1222 ms |
748 KB |
Output is correct |
43 |
Correct |
359 ms |
748 KB |
Output is correct |
44 |
Correct |
1346 ms |
660 KB |
Output is correct |
45 |
Correct |
1356 ms |
748 KB |
Output is correct |
46 |
Correct |
60 ms |
11756 KB |
Output is correct |
47 |
Correct |
542 ms |
9836 KB |
Output is correct |
48 |
Execution timed out |
1581 ms |
10092 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
8 ms |
364 KB |
Output is correct |
19 |
Correct |
32 ms |
364 KB |
Output is correct |
20 |
Correct |
35 ms |
436 KB |
Output is correct |
21 |
Correct |
5 ms |
364 KB |
Output is correct |
22 |
Correct |
4 ms |
364 KB |
Output is correct |
23 |
Correct |
3 ms |
364 KB |
Output is correct |
24 |
Correct |
7 ms |
364 KB |
Output is correct |
25 |
Correct |
5 ms |
364 KB |
Output is correct |
26 |
Correct |
33 ms |
364 KB |
Output is correct |
27 |
Correct |
23 ms |
364 KB |
Output is correct |
28 |
Correct |
10 ms |
364 KB |
Output is correct |
29 |
Correct |
34 ms |
364 KB |
Output is correct |
30 |
Correct |
35 ms |
364 KB |
Output is correct |
31 |
Correct |
2 ms |
620 KB |
Output is correct |
32 |
Correct |
7 ms |
620 KB |
Output is correct |
33 |
Correct |
112 ms |
620 KB |
Output is correct |
34 |
Correct |
1175 ms |
748 KB |
Output is correct |
35 |
Correct |
1343 ms |
748 KB |
Output is correct |
36 |
Correct |
77 ms |
620 KB |
Output is correct |
37 |
Correct |
57 ms |
620 KB |
Output is correct |
38 |
Correct |
43 ms |
492 KB |
Output is correct |
39 |
Correct |
80 ms |
620 KB |
Output is correct |
40 |
Correct |
81 ms |
620 KB |
Output is correct |
41 |
Correct |
1319 ms |
748 KB |
Output is correct |
42 |
Correct |
1222 ms |
748 KB |
Output is correct |
43 |
Correct |
359 ms |
748 KB |
Output is correct |
44 |
Correct |
1346 ms |
660 KB |
Output is correct |
45 |
Correct |
1356 ms |
748 KB |
Output is correct |
46 |
Correct |
60 ms |
11756 KB |
Output is correct |
47 |
Correct |
542 ms |
9836 KB |
Output is correct |
48 |
Execution timed out |
1581 ms |
10092 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |