Submission #685434

#TimeUsernameProblemLanguageResultExecution timeMemory
685434OrazBBigger segments (IZhO19_segments)C++14
Compilation error
0 ms0 KiB
v#include <bits/stdc++.h>
#define N 100005
#define wr cout << "Continue debugging\n";
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second
using namespace std;

int a[N], mx, n, ind[N], t[4*N];
vector<int> vec;
ll pref[N];
ll dp[N][5];

int calc(int x){
	int l = 0, r = vec.size()-1, pos = 0;
	while(l <= r){
		int md = (l+r)/2;
		if (vec[md] > x) r = md - 1;
		else{
			pos = vec[md];
			l = md + 1;
		}
	}
	return pos;
}

int binary(int i, int x){
	int l = i+1, r = n, idx=i;
	while(l <= r){
		int md = (l+r)/2;
		if (pref[md]-pref[i] >= x) r = md - 1;
		else{
			idx = md;
			l = md + 1;
		}
	}
	return idx+1;
}
// void upd(int x, int u, int v, int l, int r, int idx){
// 	if (lazy[idx]){
// 		t[idx] = lazy[idx];
// 		// if (l == 3 and r == 3 and x == 2) wr;
// 		if (l != r){
// 			lazy[idx*2] = lazy[idx];
// 			lazy[idx*2+1] = lazy[idx]; 
// 		}
// 		lazy[idx] = 0;
// 	}
// 	if (l > r or l > v or r < u) return;
// 	// if (l == 2 and r == 2) wr
// 	if (u <= l and r <= v){
// 		// cout << l << " " << r;
// 		t[idx] = x;
// 		if (l != r){
// 			lazy[idx*2] = x;
// 			lazy[idx*2+1] = x; 
// 		}
// 		return;
// 	}
// 	int md = (l+r)/2;
// 	upd(x, u, v, l, md, idx*2);
// 	upd(x, u, v, md+1, r, idx*2+1);
// 	// if (l != r)
// 	t[idx] = max(t[idx*2], t[idx*2+1]);
// }
// int range(int pos, int l, int r, int idx){
// 	if (lazy[idx]){
// 		t[idx] = lazy[idx];
// 		if (l != r){
// 			lazy[idx*2] = lazy[idx];
// 			lazy[idx*2+1] = lazy[idx]; 
// 		}
// 		lazy[idx]=0;
// 	}
// 	int md = (l+r)/2;
// 	if (l == r) return t[idx];
// 	if (md >= pos) range(pos, l, md, idx*2);
// 	else range(pos, md+1, r, idx*2+1);
// 	// t[idx] = max(t[idx*2], t[idx*2+1]);
// }
int main ()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
		pref[i] = pref[i-1]+a[i];
	}
	dp[1][1] = 1;
	dp[1][2] = a[1];
	int pos = binary(1, a[1]);
	if (pos <= n){
		ind[pos] = 1;
		vec.pb(pos);
	}
	// cout << vec[0];
	for (int i = 2; i <= n; i++){
		int pos = ind[calc(i)];
		// cout << pos;
		if (!pos){
			dp[i][1] = 1;
			dp[i][2] = pref[i];
		}else{
			dp[i][1] = dp[pos][1]+1;
			dp[i][2] = pref[i]-pref[pos];
		}
		pos = binary(i, dp[i][2]);
		if (pos > n) continue;
		ind[pos] = i;
		while(vec.size() and vec.back() >= pos){
			vec.pop_back();
		}
		vec.pb(pos);
	}
	cout << dp[n][1];
}	

Compilation message (stderr)

segments.cpp:1:2: error: stray '#' in program
    1 | v#include <bits/stdc++.h>
      |  ^
segments.cpp:1:1: error: 'v' does not name a type
    1 | v#include <bits/stdc++.h>
      | ^
segments.cpp:13:1: error: 'vector' does not name a type
   13 | vector<int> vec;
      | ^~~~~~
segments.cpp: In function 'int calc(int)':
segments.cpp:18:17: error: 'vec' was not declared in this scope
   18 |  int l = 0, r = vec.size()-1, pos = 0;
      |                 ^~~
segments.cpp:23:4: error: 'pos' was not declared in this scope
   23 |    pos = vec[md];
      |    ^~~
segments.cpp:27:9: error: 'pos' was not declared in this scope
   27 |  return pos;
      |         ^~~
segments.cpp: In function 'int main()':
segments.cpp:86:2: error: 'ios' has not been declared
   86 |  ios::sync_with_stdio(false);
      |  ^~~
segments.cpp:87:2: error: 'cin' was not declared in this scope
   87 |  cin.tie(0);
      |  ^~~
segments.cpp:98:3: error: 'vec' was not declared in this scope
   98 |   vec.pb(pos);
      |   ^~~
segments.cpp:114:9: error: 'vec' was not declared in this scope
  114 |   while(vec.size() and vec.back() >= pos){
      |         ^~~
segments.cpp:117:3: error: 'vec' was not declared in this scope
  117 |   vec.pb(pos);
      |   ^~~
segments.cpp:119:2: error: 'cout' was not declared in this scope
  119 |  cout << dp[n][1];
      |  ^~~~