首页 > 其他分享 >The 2022 ICPC Asia Regionals Online Contest (II) EJFB

The 2022 ICPC Asia Regionals Online Contest (II) EJFB

时间:2023-08-18 17:23:59浏览次数:49  
标签:__ Contest int ll Asia ICPC long cnt1 int128

The 2022 ICPC Asia Regionals Online Contest (II)

E An Interesting Sequence

232323232323

323232323232

#include<bits/stdc++.h>


using namespace std;

typedef long long ll;

void solve()
{
	ll n, k;	cin>>n>>k;
	ll res = k;
	ll t = 0;
	for(int i = 2; i <= k + 1; i++)
		if(__gcd(1ll * i, k) == 1)
		{
			t = i;
			break;
		}


	if(__gcd(t, 2ll) == 1)
	{
		res = k + t;
		n -= 2;
		res += (n / 2) * 5 + (n % 2) * 2;
	}
	else if(__gcd(t, 3ll) == 1)
	{
		res = k + t;
		n -= 2;
		res += (n / 2) * 5 + (n % 2) * 3;		
	}
	cout<<res<<'\n';

}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);	cout.tie(nullptr);

	solve();
	return 0;
}

J A Game about Increasing Sequences

能拿的区间奇偶性判断

#include<bits/stdc++.h>


using namespace std;

typedef long long ll;


const int N = 2e5 + 10;
int n, a[N], cnt1 = 0, cnt2 = 0;
void solve()
{
	cin>>n;
	for(int i = 1; i <= n; i++)
		cin>>a[i];
	cnt1 = 1;
	while(cnt1 + 1 <= n && a[cnt1 + 1] > a[cnt1])
		cnt1++;
	int j = n;
	while(j - 1 >= 1 && a[j - 1] > a[j])
		j--;
	cnt2 = n - j + 1;
	if(cnt1 % 2 == 0 && cnt2 % 2 == 0)
		cout<<"Bob\n";
	else if(cnt1 % 2 == 1 || cnt2 % 2 == 1)
		cout<<"Alice\n";
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);	cout.tie(nullptr);

	solve();
	return 0;
}

F Infinity Tree

记录每一轮产生儿子的上一轮数量,

记录产生 \(u\) 是第 \(tu\) 轮,\(v\) 同理

对 \(u\) , \(v\) 做一个 LCA, LCA 过程:

结点最大的数 \(u\),上一轮数量 \(y\), 其 \(u\) 父亲是 的 \(\dfrac{u - y}{k} + [u \% k != 0]\) ,并更新 \(tu\)

__int128 a[N];

void lca(__int128 u, __int128 v, __int128 tu, __int128 tv, __int128 &k)
{
    int cnt = 0;
    while(u != v)
    {
        ++cnt;
        //if(cnt == 10)   break;
        // write(u); cout<<"    "; write(v);   cout<<'\n';
        // write(u); cout<<"    ";     write(a[tu]); 
        // cout<<"    "; cout<<"    ";
        // write(v);  cout<<"    ";    write(a[tv]);
        // cout<<'\n';


        //write(u);   cout<<"    "; write(v);
        if(u > v)
        {
            __int128 t = u - a[tu];
           // write(a[tu]);    cout<<'\n';
            t = t / k + (t % k != 0);
            u = t;
           // write(t);   cout<<"new u\n";
            while(u <= a[tu])    tu--;
        }
        else if(u < v)
        {
            __int128 t = v - a[tv];
           // write(a[tv]);    cout<<'\n';
            t = t / k + (t % k != 0);
            v = t;
            //write(t);   cout<<"new v\n";
            while(v <= a[tv])    tv--;
        }
        // write(u); cout<<"    "; write(v);   cout<<'\n';
        //  cout<<'\n'; cout<<'\n';

    }
    write(u);
    puts("");
}
/*
1
2 6 7
*/
/*
3
2 6 7
2 4 5
3 20 2

1
2 100000000000000000 1000000000000000
*/
void solve()
{
    __int128 k, u, v;
    __int128 p, tu, tv, times;
    k = read(), u = read(), v = read();
    if(u == 1 || v == 1)
    {
        __int128 res = 1;
        write(res);
        cout<<'\n';
        return;
    }
    tu = tv = 0, p = 1, times = 0;
    while(tu == 0 || tv == 0)
    {
        times++;
        a[times] = p;
        __int128 l = p + 1, r = (k + 1) * p;
        p = r;
        // write(l); cout<<"    "; write(r);   cout<<'\n';
        if(l <= u && u <= r)    tu = times;
        if(l <= v && v <= r)    tv = times;
    }
    // cout<<'\n';
    // cout<<'\n';
    // write(tu); cout<<"  ";  write(tv);
    // cout<<'\n';
    // cout<<'\n';

    lca(u, v, tu, tv, k);
}

B Non-decreasing Array

对于两个操作都可以认为是删掉一个元素

直接dp即可

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N = 1e2 + 10;
ll n, a[N], f[N][N], b[N];
void solve()
{
	cin>>n;
	for(int i = 1; i <= n; i++)
		cin>>a[i];
	for(int i = 1; i <= n; i++)
	{
		int k = i * 2;
		ll res = 0;
		if(n - 2 - 2 * i <= 0)
		{
			cout<<(a[n] - a[1]) * (a[n] - a[1])<<'\n';
			continue;
		}
		memset(f, 0, sizeof f);
		for(int p1 = 1; p1 <= n; p1++)
			for(int q = 0; q <= k; q++)
				for(int p2 = p1 + 1; p2 - p1 - 1 + q <= k && p2 <= n; p2++)
					f[p2][p2 - p1 - 1 + q] = max(f[p1][q]  + (a[p2] - a[p1]) * (a[p2] - a[p1]),
						f[p2][p2 - p1 - 1 + q]);
					//cout<<p1 <<" "<<q<<" "<<p2<<" "<<p2 - p1 - 1 + q <<" "<<f[p2][p2 - p1 - 1 + q]<<'\n';
					//res = max(f[p2][p2 - p1 - 1 + q], res);
		for(int q = 0; q <= k; q++)
			res = max(f[n][q], res);
		cout<<res<<'\n';
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);	cout.tie(nullptr);

	solve();
	return 0;
}

标签:__,Contest,int,ll,Asia,ICPC,long,cnt1,int128
From: https://www.cnblogs.com/magicat/p/17641079.html

相关文章

  • AtCoder Beginner Contest 311 - D(思维题)
    目录D-GridIceFloorABC简单题D思维题D-GridIceFloor题意给定一个\(n\timesm\)的矩阵,矩阵每个位置上的字符要么是'.'要么是'#',保证矩阵的最外围一圈都是'#'。玩家初始位于位置(2,2)。玩家可以进行移动,但是移动有条件:玩家首先选定一个移动方向,之后在这个方......
  • The 13th Northeast Collegiate Programming Contest
    ProblemB.BalancedDiet其实就是对每种糖果从大到小的排序后,计算前缀和后再\(O(n)\)处理,由于最多只有\(n\)个糖果,所以最大复杂度是\(O(nlogn)\)。对于题目给的每种糖果的限制\(limit\),就把当前小于\(limit\)的贡献加到\(max(limit,i)\)上。vector<int>g[N];voids......
  • The 2022 ICPC Asia Regionals Online Contest (I) C L A
    The2022ICPCAsiaRegionalsOnlineContest(I)C统计度的大小,算贡献,特判\(n=1\)#include<bits/stdc++.h>usingnamespacestd;constintN=1e6+10;typedeflonglongll;intn,d[N];vector<int>e[N];llres=0;voiddfs(intu,intfrom){ ......
  • 文件解压 //problem/2928 or /contest/1709/problem/3
    字符串套递归#include<bits/stdc++.h>usingnamespacestd;chars[1005];intn,i;stringwork(){stringp;intt=0;while(++i<=n){if(s[i]>='0'&&s[i]<='9'){t=s[i]-'0......
  • 2021 ICPC 上海 DEHI
    2021ICPC上海DEHI链接:The2021ICPCAsiaShanghaiRegionalProgrammingContestD.StrangeFractions题意:给你\(p,q\),让你找正整数\(a,b\),使得\(\dfrac{p}{q}=\dfrac{a}{b}+\dfrac{b}{a}\)。如果不存在,输出\(0\)\(0\)。思路:简单数学。推柿子+\(\gcd\)因为有\(\dfrac{......
  • 议题预告 | Pulsar Summit Asia 2022:Day 2 - 英文演讲
    关于PulsarSummitPulsarSummit是ApachePulsar社区年度盛会,它将分布在世界各地的ApachePulsar项目Contributor、Committer和各企业CTO/CIO、开发者、架构师、数据科学家,以及消息和流计算社区的精英召集在一起。于此盛会,大家分享实践经验、交流想法、探讨关于Pulsar项......
  • AtCoder Beginner Contest 314
    AtCoderBeginnerContest314-AtCoderA-3.14(atcoder.jp)题目提供了100位,所以直接用字符串输出#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;signedmain(){ios::sync_with_stdio(false);cin.tie(nullptr);strings="3.14......
  • AtCoder Beginner Contest 314
    AtCoderBeginnerContest314-AtCoderA3.14voidsolve(){strings="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679";intn;cin>>n;cout<<s.substr(0,n......
  • Contest1319 - 期末习题汇总(二) 计算机基础---进制转换相关
    题目描述将十进制的1234输出将八进制的1234对应其十进制数进行输出将十六进制的1234对应其十进制数进行输出输入无输出1234D=1234D1234O=668D1234H=4660D样例输出1234D=1234D1234O=668D1234H=4660D 代码:#include<iostream>#include<iomanip>usingnamespacestd;in......
  • AtCoder Beginner Contest 314 A - Ex题解
    AtCoderBeginnerContest314A-3.14嗯,你可以用string存小数点后的...B-Roulette对于每一个金额,用个vector存pair<>存一个人赌了多少,以及是哪一个人。C-RotateColoredSubsequence每种数用个双向链表记下来。D-LOWER我们观察到,对于2,3操作,只有最后一次有用,且......