首页 > 其他分享 >Codeforces Round #818 (Div. 2) C Madoka and Formal Statement

Codeforces Round #818 (Div. 2) C Madoka and Formal Statement

时间:2022-09-03 01:45:28浏览次数:74  
标签:Madoka int ll Codeforces 818 maxn Statement include

Madoka and Formal Statement

思维

如果合法,说明 \(a_i \le b_i\),因此也可以认为 \(b_i\) 就是 \(a_i\) 最后能变成的最大值

根据题意操作,只有 \(a_i \le a_{i+1}\) 的情况,才能使 \(a_i + 1\),因此 \(a_i\) 的理论最大值应该是 \(b_{i+1} + 1\)

因此只要所有的 \(b_i\) 都不大于 \(a_i\) 的理论最大值,则成立

注意特判 \(a_i > b_i\) 的情况

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <deque>
#include <stack>
#include <ctime>
#include <cstdlib>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
const ll maxn = 2e5 + 10;
const ll inf = 1e17 + 10;
ll a[maxn], b[maxn];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        for(int i=0; i<n; i++) cin >> a[i];
        for(int i=0; i<n; i++) cin >> b[i];
        int f = 1;
        for(int i=0; i<n; i++)
        {
            int pre = i - 1, nex = i + 1;
            if(nex >= n) nex = 0;
            if(a[i] == b[i]) continue;
            if(b[i] < a[i]) f = 0;
            if(b[nex] + 1 >= b[i]) continue;
            f = 0;
        }
        if(f) cout << "YES\n";
        else cout << "NO\n";
    }
    cout << endl;
    return 0;
}

标签:Madoka,int,ll,Codeforces,818,maxn,Statement,include
From: https://www.cnblogs.com/dgsvygd/p/16651824.html

相关文章

  • Codeforces Round #818 (Div. 2) B Madoka and Underground Competitions
    MadokaandUndergroundCompetitions构造在一行里,如果选定了其中一个位置是\(X\),接下来就直接往左和往右每\(k\)个放置一个\(X\)就行了每一行的初始位置根据一开......
  • Codeforces Round #818 (Div. 2) A Madoka and Strange Thoughts
    MadokaandStrangeThoughts唯一分解定理\[gcd(a,b)=p_1^{min(ak_1,bk_1)}*p_2^{min(ak_2,bk_2)}...\]\[lcm(a,b)=p_1^{max(ak_1,bk_1)}*p_2^{max(ak_2,......
  • *Codeforces Round #651 (Div. 2) C. Number Game(博弈论)
    https://codeforces.com/contest/1370/problem/CAshishgup和FastestFinger玩游戏。他们从数字n开始,轮流玩。在每个回合中,玩家可以进行以下任意一个动作:将n除以任何大......
  • Educational Codeforces Round 123 D
    D.CrossColoring很容易想到的就是分成几个块有几个就是k多少次幂但是显然暴力的做法是n2的我们考虑如何优化我们考虑对每一行这个x[i]能成立的条件是啥那就是y[i]......
  • Educational Codeforces Round 123 E
    E.ExpandthePath我们画出一个合法的一般性的来研究比如RDRDR我们可以将其任意一个往下往右延长但是这个图形获得的面积是不规则的但是我们知道合法的序列肯定是......
  • Codeforces Round #814 (Div. 2)
    Preface关于军训……它死了第一次感觉到疫情的好处,就是不知道训了一半给不给学分,要不要补训一直打隔膜颓废也不是办法,因此来写写题(才不是因为路由器没到舍不得用流量更......
  • Educational Codeforces Round 134 (Rated for Div. 2) D Maximum AND
    MaximumAND贪心从高位开始,尽可能地让\(a\)中该位为\(0\)的和\(b\)中该位为\(1\)的配对在一起,换句话说,可以让\(a\)由小到大排序,\(b\)由大到小排序如果当......
  • codeforces极简题解
    CF1713F利用lucas定理,\(b_S\)表示下标\(T\)与\(S\)无交的\(a_T\)的异或,由于部分\(b_S\)未知,不能直接iFWT。回顾容斥:\([S=\emptyset]=\sum_{T\subseteqS}(-1)^|T|\),\([n=0......
  • Codeforces Round #773 E
    AnonymityIsImportant我们最开始会想到用三个状态表示其实并不用我们只需要用0表示这个人没病1表示不确定有病(这样我们就可以用set来做了)要是一个区间给了有病我们......
  • Educational Codeforces Round 134 (Rated for Div. 2)
    DMaxiumAnd贪心,优先满足高位,每次判断是否能够满足这一位答案为1,如果能则更新答案,这样显然是优的EPrefixFunction模仿求前缀函数的算法,先预处理求出\(|S|\)的前缀函......