Submission #252054

# Submission time Handle Problem Language Result Execution time Memory
252054 2020-07-24T04:34:33 Z errorgorn Building Bridges (CEOI17_building) C++14
60 / 100
112 ms 15736 KB
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

struct line{
	ll m,c;
	
	line (ll _m,ll _c){
		m=_m,c=_c;
	}
	
	ll get(ll x){
		return m*x+c;
	}
};

struct node{
	int s,e,m; //[s,e)
	line val=line(0,1e18);
	node *l,*r;
	
	node (int _s,int _e){
		s=_s,e=_e,m=s+e>>1;
		
		if (e-s>1){
			l=new node(s,m);
			r=new node(m,e);
		}
	}
	
	void update(line i){
		bool left=i.get(s)<val.get(s);
		bool mid=i.get(m)<val.get(m);
		
		if (mid) swap(i,val);
		
		if (e-s>1){
			if (left!=mid) l->update(i);
			else r->update(i);
		}
	}
	
	ll query(ll x){
		if (e-s==1) return val.get(x);
		else if (x<m) return min(l->query(x),val.get(x));
		else return min(r->query(x),val.get(x));
	}
} *root=new node(0,100005);

ll sq(ll i){
	return i*i;
}

int n;
ll h[100005];
ll w[100005]; //actuall pref

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	rep(x,1,n+1) cin>>h[x];
	rep(x,1,n+1){
		cin>>w[x];
		w[x]+=w[x-1];
	}
	
	root->update(line(-2*h[1],sq(h[1])-w[1]));
	
	ll ans;
	rep(x,2,n+1){
		ans=root->query(h[x])+sq(h[x])+w[x-1];
		//cout<<ans<<endl;
		root->update(line(-2*h[x],sq(h[x])-w[x]+ans));
	}
	
	cout<<ans<<endl;
}

Compilation message

building.cpp: In constructor 'node::node(int, int)':
building.cpp:52:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   s=_s,e=_e,m=s+e>>1;
               ~^~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12928 KB Output is correct
2 Correct 13 ms 12928 KB Output is correct
3 Correct 11 ms 12928 KB Output is correct
4 Correct 11 ms 12928 KB Output is correct
5 Correct 11 ms 12928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 15480 KB Output is correct
2 Correct 62 ms 15488 KB Output is correct
3 Correct 55 ms 15608 KB Output is correct
4 Correct 55 ms 15352 KB Output is correct
5 Correct 64 ms 15352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12928 KB Output is correct
2 Correct 13 ms 12928 KB Output is correct
3 Correct 11 ms 12928 KB Output is correct
4 Correct 11 ms 12928 KB Output is correct
5 Correct 11 ms 12928 KB Output is correct
6 Correct 55 ms 15480 KB Output is correct
7 Correct 62 ms 15488 KB Output is correct
8 Correct 55 ms 15608 KB Output is correct
9 Correct 55 ms 15352 KB Output is correct
10 Correct 64 ms 15352 KB Output is correct
11 Correct 106 ms 15608 KB Output is correct
12 Correct 103 ms 15608 KB Output is correct
13 Correct 60 ms 15484 KB Output is correct
14 Correct 112 ms 15736 KB Output is correct
15 Incorrect 62 ms 15352 KB Output isn't correct
16 Halted 0 ms 0 KB -