Submission #566849

# Submission time Handle Problem Language Result Execution time Memory
566849 2022-05-23T03:59:23 Z errorgorn Sightseeing in Kyoto (JOI22_kyoto) C++17
100 / 100
418 ms 20028 KB
// Super Idol的笑容
//    都没你的甜
//  八月正午的阳光
//    都没你耀眼
//  热爱105°C的你
// 滴滴清纯的蒸馏水

#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 int long long
#define ll long long
#define ii pair<ll,ll>
#define iii pair<double,ii>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << ": " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound

#define rep(x,start,end) for(int 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()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

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

int n,m;
int arr[100005];
int brr[100005];

set<int> s1,s2;
priority_queue<iii,vector<iii>,greater<iii> > pq1,pq2;

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);
	
	cin>>n>>m;
	rep(x,1,n+1) cin>>arr[x];
	rep(x,1,m+1) cin>>brr[x];
	
	rep(x,1,n+1) s1.insert(x);
	rep(x,1,m+1) s2.insert(x);
	
	rep(x,1,n) pq1.push({arr[x]-arr[x+1],ii(x,x+1)});
	rep(x,1,m) pq2.push({brr[x]-brr[x+1],ii(x,x+1)});
	
	pq1.push({1e18,ii(-1,-1)});
	pq2.push({1e18,ii(-1,-1)});
	
	int ans=0;
	while (sz(pq1)+sz(pq2)>2){
		if (pq1.top()<pq2.top()){
			ii p=pq1.top().se; pq1.pop();
			if (!s1.count(p.fi) || !s1.count(p.se)) continue;
			
			int l=p.fi;
			int r=-1;
			auto it=s1.find(p.se);
			if (it!=--s1.end()) r=*next(it);
			s1.erase(it);
			
			if (r!=-1) pq1.push({(double)(arr[l]-arr[r])/(r-l),ii(l,r)});
			else ans+=brr[*s2.rbegin()]*(p.se-p.fi);
		}
		else{
			ii p=pq2.top().se; pq2.pop();
			if (!s2.count(p.fi) || !s2.count(p.se)) continue;
			
			int l=p.fi;
			int r=-1;
			auto it=s2.find(p.se);
			if (it!=--s2.end()) r=*next(it);
			s2.erase(it);
			
			if (r!=-1) pq2.push({(double)(brr[l]-brr[r])/(r-l),ii(l,r)});
			else ans+=arr[*s1.rbegin()]*(p.se-p.fi);
		}
	}
	
	cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 472 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 328 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 121 ms 8292 KB Output is correct
5 Correct 62 ms 7944 KB Output is correct
6 Correct 42 ms 3920 KB Output is correct
7 Correct 352 ms 18952 KB Output is correct
8 Correct 387 ms 18888 KB Output is correct
9 Correct 377 ms 19004 KB Output is correct
10 Correct 393 ms 18876 KB Output is correct
11 Correct 138 ms 18832 KB Output is correct
12 Correct 369 ms 18908 KB Output is correct
13 Correct 372 ms 19008 KB Output is correct
14 Correct 258 ms 18888 KB Output is correct
15 Correct 128 ms 19092 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 472 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 328 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 121 ms 8292 KB Output is correct
33 Correct 62 ms 7944 KB Output is correct
34 Correct 42 ms 3920 KB Output is correct
35 Correct 352 ms 18952 KB Output is correct
36 Correct 387 ms 18888 KB Output is correct
37 Correct 377 ms 19004 KB Output is correct
38 Correct 393 ms 18876 KB Output is correct
39 Correct 138 ms 18832 KB Output is correct
40 Correct 369 ms 18908 KB Output is correct
41 Correct 372 ms 19008 KB Output is correct
42 Correct 258 ms 18888 KB Output is correct
43 Correct 128 ms 19092 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 336 KB Output is correct
55 Correct 143 ms 9136 KB Output is correct
56 Correct 2 ms 468 KB Output is correct
57 Correct 9 ms 1424 KB Output is correct
58 Correct 31 ms 2900 KB Output is correct
59 Correct 366 ms 20020 KB Output is correct
60 Correct 402 ms 19896 KB Output is correct
61 Correct 365 ms 19744 KB Output is correct
62 Correct 397 ms 19836 KB Output is correct
63 Correct 147 ms 19744 KB Output is correct
64 Correct 381 ms 19988 KB Output is correct
65 Correct 418 ms 20028 KB Output is correct
66 Correct 170 ms 20028 KB Output is correct
67 Correct 144 ms 19336 KB Output is correct