The 22nd Japanese Olympiad in Informatics (JOI 2022/2023) Final Round 题解

Posted nike0good

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了The 22nd Japanese Olympiad in Informatics (JOI 2022/2023) Final Round 题解相关的知识,希望对你有一定的参考价值。

交题:https://cms.ioi-jp.org/documentation

A

给一个序列 a 1 , ⋯   , a n a_1,\\cdots,a_n a1,,an
执行 n n n个操作,第 i i i个操作为找出第 i i i个数前离其最近且与它相同的数的位置,把这两个数之间的数全部赋值 a i a_i ai。求最后的序列。

考虑第 i i i个操作执行完后, i i i之前每个数一定是连续出现正好一段或不出现。

#include<bits/stdc++.h> 
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n)  \\
						For(j,m-1) cout<<a[i][j]<<' ';\\
						cout<<a[i][m]<<endl; \\
						 
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b)return (a*b)%F;
ll add(ll a,ll b)return (a+b)%F;
ll sub(ll a,ll b)return ((a-b)%F+F)%F;
void upd(ll &a,ll b)a=(a%F+b%F)%F;
inline int read()

	int x=0,f=1; char ch=getchar();
	while(!isdigit(ch)) if (ch=='-') f=-1; ch=getchar();
	while(isdigit(ch))  x=x*10+ch-'0'; ch=getchar();
	return x*f;
 
int a[201000];
map<int,pair<int,int> > h;
int main()

//	freopen("A.in","r",stdin);
//	freopen(".out","w",stdout);
	int n=read();
	For(i,n) a[i]=read();	
	stack <pair<pair<int,int> , int > > st;
	For(i,n) 
		if(st.empty() || !h.count(a[i]) || h[a[i]] ==mp(0,0) ) 
			st.push(mp(mp(i,i),a[i]));
			h[a[i]]=mp(i,i);
		else 
			while(!st.empty()) 
				auto p=st.top();st.pop();
				if(p.se==a[i]) 
					h[p.se]=mp(p.fi.fi,i);
					st.push(mp(h[p.se],a[i]));
					break;
				else 
					h[p.se]=mp(0,0);
				
			
		
	
	while(!st.empty()) 
		auto p=st.top();st.pop();
		Fork(i,p.fi.fi,p.fi.se) a[i]=p.se;
	
	For(i,n) cout<<a[i]<<endl;
	
	return 0;


B

n n n个点对,每个点对 ( x , y ) (x,y) (x,y)可以覆盖 S = ( a , b ) ∣ b < = y , ∣ a − x ∣ < = y − b S=(a,b)|b<=y,|a-x|<=y-b S=(a,b)b<=y,ax<=yb。问取多少个点对能覆盖所有点对。

经典题

#include<bits/stdc++.h> 
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n)  \\
						For(j,m-1) cout<<a[i][j]<<' ';\\
						cout<<a[i][m]<<endl; \\
						 
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b)return (a*b)%F;
ll add(ll a,ll b)return (a+b)%F;
ll sub(ll a,ll b)return ((a-b)%F+F)%F;
void upd(ll &a,ll b)a=(a%F+b%F)%F;sh Alle Olympia Streams des ZDF nebeneinander auf dem Desktop。 MPV Playerwirdbenötigt。

The 62nd Spark Club Meeting: Toy

E.Rescheduling the Exam

E.Rescheduling the Exam

Old Photos--Microsoft Toastmasters Club the 181nd Meeting

C - The C Answer (2nd Edition) - Exercise 1-2