Submission #1115075

# Submission time Handle Problem Language Result Execution time Memory
1115075 2024-11-20T02:20:28 Z 8pete8 Sightseeing in Kyoto (JOI22_kyoto) C++17
100 / 100
128 ms 19248 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<cassert>
#include<unordered_map>
#include <queue>
#include <cstdint>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
#define int long long
using namespace std;
const int mod=998244353,mxn=2e5+5,inf=1e18,minf=-1e18,lg=30;
int n,k,m,q;
void setIO(string name){		
	ios_base::sync_with_stdio(0); cin.tie(0);		
	freopen((name+".in").c_str(),"r",stdin);		
	freopen((name+".out").c_str(),"w",stdout);
}
struct node{
	int c0,c1;
	bool operator<(node a)const{return (c0*a.c1)<(c1*a.c0);}
};
int A[mxn+10],B[mxn+10],P[mxn+10],pa[mxn+10],vis[mxn+10];
node have[mxn+10];
int find(int u){
	return ((u==pa[u])?u:pa[u]=find(pa[u]));
}
void merge(int a,int b){
	a=find(a),b=find(b);
	if(a==b)return;
    pa[b]=a;
}
int32_t main(){
    fastio
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>A[i];
	for(int i=1;i<=m;i++)cin>>B[i];
    for(int i=0;i<=n+m+1;i++)pa[i]=i;
	priority_queue<pair<node,int>>pq;
	int ans=0;
	for(int i=2;i<=n;i++){
		P[i]=i-1;
        ans-=A[i-1];//subtract overcount inversion -> constant
		have[i]=(node){1,A[i]-A[i-1]};
		pq.push({have[i],i});
	}
	for(int i=2;i<=m;i++){
		if(i==2)P[i+n]=0;
		else P[i+n]=i+n-1;
        ans-=B[i-1];
		have[i+n]=(node){1,B[i]-B[i-1]};
		pq.push({have[i+n],i+n});
	}
    have[0].c0=2;
    have[0].c1=B[1]+A[1];
	while(!pq.empty()){
		int cur=pq.top().s;
		node x=pq.top().f;
		pq.pop();
		if(have[cur].c1!=x.c1||have[cur].c0!=x.c0)continue;
		if(vis[cur])continue;
		vis[cur]=1;
		ans+=have[find(P[cur])].c1*x.c0;
		have[find(P[cur])].c1+=x.c1;
		have[find(P[cur])].c0+=x.c0;
        merge((P[cur]),cur);
		if(find(P[cur])!=0)pq.push({have[find(P[cur])],find(P[cur])});
	}
	cout<<ans;
}
/*

*/

Compilation message

kyoto.cpp:32:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
   32 | #pragma GCC optimize ("03,unroll-lopps")
      |                                        ^
kyoto.cpp:37:23: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   37 | void setIO(string name){
      |                       ^
kyoto.cpp:44:24: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   44 |  bool operator<(node a)const{return (c0*a.c1)<(c1*a.c0);}
      |                        ^~~~~
kyoto.cpp:48:15: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   48 | int find(int u){
      |               ^
kyoto.cpp:51:23: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   51 | void merge(int a,int b){
      |                       ^
kyoto.cpp:56:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   56 | int32_t main(){
      |              ^
kyoto.cpp: In function 'void setIO(std::string)':
kyoto.cpp:39:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kyoto.cpp:40:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 1 ms 6624 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 2 ms 6736 KB Output is correct
5 Correct 1 ms 6620 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 1 ms 6480 KB Output is correct
9 Correct 2 ms 6736 KB Output is correct
10 Correct 2 ms 6648 KB Output is correct
11 Correct 2 ms 6736 KB Output is correct
12 Correct 2 ms 6736 KB Output is correct
13 Correct 2 ms 6628 KB Output is correct
14 Correct 2 ms 6904 KB Output is correct
15 Correct 2 ms 6736 KB Output is correct
16 Correct 2 ms 6640 KB Output is correct
17 Correct 2 ms 6736 KB Output is correct
18 Correct 1 ms 6480 KB Output is correct
19 Correct 1 ms 6480 KB Output is correct
20 Correct 1 ms 6480 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 1 ms 6648 KB Output is correct
23 Correct 1 ms 6480 KB Output is correct
24 Correct 2 ms 6480 KB Output is correct
25 Correct 1 ms 6480 KB Output is correct
26 Correct 1 ms 6480 KB Output is correct
27 Correct 1 ms 6480 KB Output is correct
28 Correct 1 ms 6480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 2 ms 6736 KB Output is correct
4 Correct 44 ms 12732 KB Output is correct
5 Correct 30 ms 12740 KB Output is correct
6 Correct 19 ms 10440 KB Output is correct
7 Correct 115 ms 17844 KB Output is correct
8 Correct 111 ms 17936 KB Output is correct
9 Correct 115 ms 17852 KB Output is correct
10 Correct 108 ms 17856 KB Output is correct
11 Correct 81 ms 17892 KB Output is correct
12 Correct 121 ms 17852 KB Output is correct
13 Correct 118 ms 17852 KB Output is correct
14 Correct 79 ms 17848 KB Output is correct
15 Correct 83 ms 18124 KB Output is correct
16 Correct 2 ms 6648 KB Output is correct
17 Correct 1 ms 6648 KB Output is correct
18 Correct 1 ms 6480 KB Output is correct
19 Correct 2 ms 6480 KB Output is correct
20 Correct 2 ms 6480 KB Output is correct
21 Correct 1 ms 6480 KB Output is correct
22 Correct 1 ms 6480 KB Output is correct
23 Correct 2 ms 6480 KB Output is correct
24 Correct 2 ms 6480 KB Output is correct
25 Correct 1 ms 6480 KB Output is correct
26 Correct 2 ms 6480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 1 ms 6624 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 2 ms 6736 KB Output is correct
5 Correct 1 ms 6620 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 1 ms 6480 KB Output is correct
9 Correct 2 ms 6736 KB Output is correct
10 Correct 2 ms 6648 KB Output is correct
11 Correct 2 ms 6736 KB Output is correct
12 Correct 2 ms 6736 KB Output is correct
13 Correct 2 ms 6628 KB Output is correct
14 Correct 2 ms 6904 KB Output is correct
15 Correct 2 ms 6736 KB Output is correct
16 Correct 2 ms 6640 KB Output is correct
17 Correct 2 ms 6736 KB Output is correct
18 Correct 1 ms 6480 KB Output is correct
19 Correct 1 ms 6480 KB Output is correct
20 Correct 1 ms 6480 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 1 ms 6648 KB Output is correct
23 Correct 1 ms 6480 KB Output is correct
24 Correct 2 ms 6480 KB Output is correct
25 Correct 1 ms 6480 KB Output is correct
26 Correct 1 ms 6480 KB Output is correct
27 Correct 1 ms 6480 KB Output is correct
28 Correct 1 ms 6480 KB Output is correct
29 Correct 1 ms 6480 KB Output is correct
30 Correct 2 ms 6480 KB Output is correct
31 Correct 2 ms 6736 KB Output is correct
32 Correct 44 ms 12732 KB Output is correct
33 Correct 30 ms 12740 KB Output is correct
34 Correct 19 ms 10440 KB Output is correct
35 Correct 115 ms 17844 KB Output is correct
36 Correct 111 ms 17936 KB Output is correct
37 Correct 115 ms 17852 KB Output is correct
38 Correct 108 ms 17856 KB Output is correct
39 Correct 81 ms 17892 KB Output is correct
40 Correct 121 ms 17852 KB Output is correct
41 Correct 118 ms 17852 KB Output is correct
42 Correct 79 ms 17848 KB Output is correct
43 Correct 83 ms 18124 KB Output is correct
44 Correct 2 ms 6648 KB Output is correct
45 Correct 1 ms 6648 KB Output is correct
46 Correct 1 ms 6480 KB Output is correct
47 Correct 2 ms 6480 KB Output is correct
48 Correct 2 ms 6480 KB Output is correct
49 Correct 1 ms 6480 KB Output is correct
50 Correct 1 ms 6480 KB Output is correct
51 Correct 2 ms 6480 KB Output is correct
52 Correct 2 ms 6480 KB Output is correct
53 Correct 1 ms 6480 KB Output is correct
54 Correct 2 ms 6480 KB Output is correct
55 Correct 51 ms 13252 KB Output is correct
56 Correct 2 ms 6736 KB Output is correct
57 Correct 6 ms 7244 KB Output is correct
58 Correct 15 ms 9928 KB Output is correct
59 Correct 128 ms 18876 KB Output is correct
60 Correct 121 ms 18864 KB Output is correct
61 Correct 113 ms 19188 KB Output is correct
62 Correct 114 ms 19120 KB Output is correct
63 Correct 78 ms 18876 KB Output is correct
64 Correct 110 ms 19132 KB Output is correct
65 Correct 117 ms 19132 KB Output is correct
66 Correct 80 ms 18876 KB Output is correct
67 Correct 86 ms 19248 KB Output is correct