Submission #173494

# Submission time Handle Problem Language Result Execution time Memory
173494 2020-01-04T09:35:19 Z juggernaut Bigger segments (IZhO19_segments) C++14
13 / 100
3 ms 380 KB
#include <bits/stdc++.h>

#define ll long long
#define int long long int
using namespace std;

const int N = (int)100001;

int n;
int a[N], dp[N], ind[N];
ll pref[N];
 int t[4*N];
 void build(int v,int l,int r){
      if(l==r){
            t[v]=1e9;
            return;
      }
      int mid=(l+r)>>1;
      build(2*v,l,mid);
      build(2*v+1,mid+1,r);
      t[v]=1e9;
}
 void update(int v,int l,int r,int pos,int val){
      if(l==pos&&r==pos){
            t[v]=val;
            return;
      }
      int mid=(l+r)>>1;
      if(pos<=mid)update(2*v,l,mid,pos,val);
      else update(2*v+1,mid+1,r,pos,val);
      t[v]=min(t[v*2],t[v*2+1]);
}
int get(int v,int l,int r,int ql,int qr){
      if(ql<=l&&r<=qr)return t[v];
      if(r<ql||qr<l)return 1e9;
      int mid=(l+r)>>1;
      return min(get(v*2,l,mid,ql,qr),get(v*2+1,mid+1,r,ql,qr));
}
main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		pref[i] = pref[i - 1] + a[i];
	}
	build(1,0,n);
	update(1,0,n,0,0);
	for (int i = 1; i <= n; i++) {
		dp[i] = dp[i - 1];
		ind[i] = ind[i - 1];
		int l = 0,r=i-1,mid;
		while(l<r){
            mid=(l+r+1)>>1;
            if(pref[i]>=get(1,0,n,mid,i-1))l=mid;
            else r=mid-1;
		}
		/*for (int j = 0; j < i; j++) {
			if (pref[i] >= 2 * pref[j] - pref[ind[j]]) {
				l = j;
			}
		}*/

		update(1,0,n,i,2*pref[i]-pref[l]);
		dp[i] = dp[l] + 1;
		ind[i] = l;
	}
	// cerr << ind[4] << endl;
	cout << dp[n];
}

Compilation message

segments.cpp:39:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
segments.cpp: In function 'int main()':
segments.cpp:40:16: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
  scanf("%d", &n);
              ~~^
segments.cpp:42:20: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   scanf("%d", &a[i]);
               ~~~~~^
segments.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
segments.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Incorrect 3 ms 376 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Incorrect 3 ms 376 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Incorrect 3 ms 376 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Incorrect 3 ms 376 KB Output isn't correct
18 Halted 0 ms 0 KB -