Submission #302383

# Submission time Handle Problem Language Result Execution time Memory
302383 2020-09-18T16:11:04 Z errorgorn Discharging (NOI20_discharging) C++14
100 / 100
171 ms 22952 KB
#include <bits/stdc++.h>

using namespace std;



#define ll long long

#define ii pair<int,int>

#define fi first

#define se second

#define endl '\n'



#define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);(s<e?x++:x--))

#define sz(x) (int) (x).size()

#define all(x) (x).begin(),(x).end()



struct line{

	ll m,c;

	

	line (ll _m,ll _c){

		m=_m,c=_c;

	}

	

	ll get(ll x){

		return m*x+c;

	}

};



struct LCH{	

	deque<line> dq;

	

	double POI(line i,line j){

		return (double)(i.c-j.c)/(double)(j.m-i.m);

	}

	

	void insert(line i){

		//cout<<"debug: "<<i.m<<" "<<i.c<<endl;

		

		while (sz(dq)>=2 && POI(dq.back(),i)<POI(dq[sz(dq)-2],dq.back())) dq.pop_back();

		dq.push_back(i);

		

		//for (auto &it:dq) cout<<it.m<<"_"<<it.c<<" ";cout<<endl;

	}

	

	ll query(ll x){

		while (sz(dq)>=2 && POI(dq[0],dq[1])<x) dq.pop_front();

		

		return dq.front().get(x);

	}

} hull=LCH();



int n;

ll arr[1000005];

vector<ii> v;



int main(){

	cin.tie(0);

	cout.tie(0);

	ios::sync_with_stdio(false);

	

	cin>>n;

	rep(x,0,n){

		cin>>arr[x];

		if (v.empty() || v.back().fi<arr[x]){

			v.push_back(ii(arr[x],1));

		}

		else{

			v.back().se++;

		}

	}

	

	ll pw=0;

	

	//for (auto &it:v) cout<<it.fi<<" "<<it.se<<endl;

	

	for (auto &it:v) pw+=it.se;

	

	hull.insert(line(pw,0));

	

	ll ans=0;

	for (auto &it:v){

		ans=hull.query(it.fi);

		

		//cout<<ans<<endl;

		pw-=it.se;

		hull.insert(line(pw,ans));

	}

	

	cout<<ans<<endl;

}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 416 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 388 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 416 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 388 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 115 ms 16508 KB Output is correct
17 Correct 123 ms 17784 KB Output is correct
18 Correct 100 ms 16620 KB Output is correct
19 Correct 122 ms 17536 KB Output is correct
20 Correct 117 ms 17768 KB Output is correct
21 Correct 115 ms 17640 KB Output is correct
22 Correct 111 ms 16868 KB Output is correct
23 Correct 129 ms 21856 KB Output is correct
24 Correct 125 ms 22340 KB Output is correct
25 Correct 126 ms 22952 KB Output is correct
26 Correct 133 ms 21144 KB Output is correct
27 Correct 132 ms 16232 KB Output is correct
28 Correct 117 ms 17896 KB Output is correct
29 Correct 128 ms 22464 KB Output is correct
30 Correct 136 ms 21440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 17784 KB Output is correct
2 Correct 119 ms 17888 KB Output is correct
3 Correct 118 ms 17952 KB Output is correct
4 Correct 122 ms 17784 KB Output is correct
5 Correct 122 ms 17856 KB Output is correct
6 Correct 116 ms 17856 KB Output is correct
7 Correct 124 ms 17904 KB Output is correct
8 Correct 115 ms 17784 KB Output is correct
9 Correct 167 ms 17800 KB Output is correct
10 Correct 171 ms 17808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 416 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 388 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 416 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 416 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 388 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 115 ms 16508 KB Output is correct
31 Correct 123 ms 17784 KB Output is correct
32 Correct 100 ms 16620 KB Output is correct
33 Correct 122 ms 17536 KB Output is correct
34 Correct 117 ms 17768 KB Output is correct
35 Correct 115 ms 17640 KB Output is correct
36 Correct 111 ms 16868 KB Output is correct
37 Correct 129 ms 21856 KB Output is correct
38 Correct 125 ms 22340 KB Output is correct
39 Correct 126 ms 22952 KB Output is correct
40 Correct 133 ms 21144 KB Output is correct
41 Correct 132 ms 16232 KB Output is correct
42 Correct 117 ms 17896 KB Output is correct
43 Correct 128 ms 22464 KB Output is correct
44 Correct 136 ms 21440 KB Output is correct
45 Correct 118 ms 17784 KB Output is correct
46 Correct 119 ms 17888 KB Output is correct
47 Correct 118 ms 17952 KB Output is correct
48 Correct 122 ms 17784 KB Output is correct
49 Correct 122 ms 17856 KB Output is correct
50 Correct 116 ms 17856 KB Output is correct
51 Correct 124 ms 17904 KB Output is correct
52 Correct 115 ms 17784 KB Output is correct
53 Correct 167 ms 17800 KB Output is correct
54 Correct 171 ms 17808 KB Output is correct
55 Correct 1 ms 384 KB Output is correct
56 Correct 1 ms 384 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 1 ms 416 KB Output is correct
67 Correct 1 ms 384 KB Output is correct
68 Correct 1 ms 384 KB Output is correct
69 Correct 1 ms 384 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 1 ms 384 KB Output is correct
73 Correct 1 ms 384 KB Output is correct
74 Correct 1 ms 384 KB Output is correct
75 Correct 1 ms 384 KB Output is correct
76 Correct 139 ms 14128 KB Output is correct
77 Correct 97 ms 14204 KB Output is correct
78 Correct 94 ms 13560 KB Output is correct
79 Correct 96 ms 13816 KB Output is correct
80 Correct 110 ms 14452 KB Output is correct
81 Correct 92 ms 13688 KB Output is correct
82 Correct 95 ms 13688 KB Output is correct
83 Correct 97 ms 14200 KB Output is correct
84 Correct 96 ms 14000 KB Output is correct
85 Correct 96 ms 14200 KB Output is correct
86 Correct 111 ms 13676 KB Output is correct
87 Correct 94 ms 13556 KB Output is correct
88 Correct 97 ms 13944 KB Output is correct
89 Correct 98 ms 13664 KB Output is correct
90 Correct 93 ms 13688 KB Output is correct
91 Correct 102 ms 13432 KB Output is correct
92 Correct 145 ms 18912 KB Output is correct
93 Correct 122 ms 17632 KB Output is correct
94 Correct 90 ms 13048 KB Output is correct
95 Correct 101 ms 14584 KB Output is correct
96 Correct 95 ms 13524 KB Output is correct
97 Correct 97 ms 13816 KB Output is correct
98 Correct 106 ms 13944 KB Output is correct
99 Correct 96 ms 13560 KB Output is correct
100 Correct 134 ms 13688 KB Output is correct