首页 > 其他分享 >E. Klee's SUPER DUPER LARGE Array!!!

E. Klee's SUPER DUPER LARGE Array!!!

时间:2024-09-09 11:46:20浏览次数:5  
标签:200005 int DUPER st LARGE next low Array now

原题链接

题解

发现随着 \(i\) 越大,绝对符号内的值越大,因此具有单调性,可以应用二分查找找离0最近的 \(i\)

而值可以用 等差数列求和公式 快速求出

code


#include<bits/stdc++.h>
using namespace std;
/*
mt19937_64 rnd(time(0));
#define double long double
#define lowbit(x) ((x)&(-x))
const int inf=1e18;
const int mod=1e9+7;

const int N=4e5;
int qpow(int a,int n)
{
    int res=1;
    while(n)
    {
        if(n&1) res=res*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return res;
}
int inv(int x)
{
    return qpow(x,mod-2);
}
int fa[2000005];
int finds(int now) { return now == fa[now] ? now :fa[now]=finds(fa[now]); }

vector<int> G[200005];

int dfn[200005],low[200005];
int cnt=0,num=0;
int in_st[200005]={0};
stack<int> st;
int belong[200005]={0};

void scc(int now,int fa)
{
    dfn[now]=++cnt;
    low[now]=dfn[now];
    in_st[now]=1;
    st.push(now);

    for(auto next:G[now])
    {
        if(next==fa) continue;

        if(!dfn[next])
        {
            scc(next,now);
            low[now]=min(low[now],low[next]);
        }
        else if(in_st[next])
        {
            low[now]=min(low[now],dfn[next]);
        }
    }

    if(low[now]==dfn[now])
    {
        int x;
        num++;
        do
        {
            x=st.top();
            st.pop();
            in_st[x]=0;
            belong[x]=num;
        }while(x!=now);
    }
}
vector<int> prime;
bool mark[200005]={0};
void shai()
{
    for(int i=2;i<=200000;i++)
    {
        if(!mark[i]) prime.push_back(i);

        for(auto it:prime)
        {
            if(it*i>200000) break;

            mark[it*i]=1;
            if(it%i==0) break;
        }
    }
}
*/

#define int long long


int cal(int n,int k,int i)
{
    int add=(k+k+i-1)*i/2;
    int jian=(k+i+k+n-1)*(n-i)/2;

    return add-jian;
}

void solve()
{
    int n,k;
    cin>>n>>k;

    int l=0,r=n+1;

    while(l+1<r)
    {
        int mid=(l+r)/2;

        if(cal(n,k,mid)>=0) r=mid;
        else l=mid;
    }

    cout<<min(abs(cal(n,k,l)),abs(cal(n,k,r)))<<'\n';
}
signed main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int TT=1;
    cin>>TT;
    while(TT--) solve();
    return 0;
}


标签:200005,int,DUPER,st,LARGE,next,low,Array,now
From: https://www.cnblogs.com/pure4knowledge/p/18404284

相关文章

  • Java中的集合框架深度解析:从ArrayList到ConcurrentHashMap的性能考量
    Java中的集合框架深度解析:从ArrayList到ConcurrentHashMap的性能考量大家好,我是微赚淘客返利系统3.0的小编,是个冬天不穿秋裤,天冷也要风度的程序猿!Java的集合框架为开发者提供了多种数据结构,每种数据结构都有其特定的使用场景和性能特征。本文将深度解析Java中的主要集合类,从Array......
  • 题解:AT_abc369_c [ABC369C] Count Arithmetic Subarrays
    很水的一道题,但是硬控我半个小时呜呜呜。它问等差数列的数量,我们发现只要找到所有的等差数列,那么答案一定包含在这些数列的连续子序列中。求所有等差数列显然可以线性,我们求出每个等差数列的长度\(n\),那么连续子序列个数即为\(n(n+1)\over2\)。至于求的话我定义了两个指针,每......
  • LeetCode //C - 350. Intersection of Two Arrays II
    350.IntersectionofTwoArraysIIGiventwointegerarraysnums1andnums2,returnanarrayoftheirintersection.Eachelementintheresultmustappearasmanytimesasitshowsinbotharraysandyoumayreturntheresultinanyorder. Example1:......
  • A Comprehensive Survey of Accelerated Generation Techniques in Large Language Mo
    本文是LLM系列文章,针对《AComprehensiveSurveyofAcceleratedGenerationTechniquesinLargeLanguageModels》的翻译。大型语言模型中加速生成技术的全面调查摘要1引言2推测解码3早退4非自回归模型5讨论和局限性6结论摘要尽管在大型语言模型(L......
  • A COMPREHENSIVE SURVEY ON EVALUATING LARGE LANGUAGE MODEL APPLICATIONS IN THE ME
    本文是LLM系列文章,针对《ACOMPREHENSIVESURVEYONEVALUATINGLARGELANGUAGEMODELAPPLICATIONSINTHEMEDICALINDUSTRY》的翻译。关于评估医疗行业中大型语言模型应用程序的综合调查摘要1引言和背景2综述的分类和结构3医学领域LLM应用评估的现状4挑战......
  • CF2009G. Yunli's Subarray Queries 题解
    G1题目要求,对于一个子区间$a_{l\siml+k-1}$,最少要进行多少次单点修改,才能使$\forall\l<i\leql+k-1,a_i=a_{i-1}+1$,其中$k$是固定的。对于这种问题,我们通常有一个trick:将$a_i$变为$a_i-i$。这样的话,我们要求的答案就变为了$k$减去变化后的$a_{l\siml+k-1}$......
  • 6.科学计算模块Numpy(3)对ndarray数组的常用操作
    引言众所周知,numpy能作为python中最受欢迎的数据处理模块,脱离不了它最核心的部件——ndarray数组。那么,我们今天就来了解一下numpy中对ndarray的常用操作。通过阅读本篇博客你可以:1.掌握ndarray数组的切片和copy2.学会如何改变ndarray的数组维度3.掌握数组的拼接一、ndar......
  • AngularJS进阶(十五)Cookie ‘data‘ possibly not set or overflowed because it was
    Cookie ‘data’ possibly not set or overflowedbecause it was too large (5287 > 4096 bytes)!注:请点击此处进行充电!故事起源项目开发过程中遇到以上问题,刚开始以为只是个警告,没太在意。后来发现直接影响到了程序的执行效果。果断寻找解决方法。问题......
  • Array List与顺序表
    学习目标线性表顺序表与链表的简单了解ArrayList的介绍ArrayList的扩容机制 线性表线性表(linearlist):是由n且具有相同的特性数据元素的有限列表,线性表在实际运用中常见的数据结构,常见的线性表:栈,堆,队列,顺序表,链表…链表:在逻辑上是连续的数据结......
  • ArrayList和LinkedList的区别
    >List子体系特点:A:有序的(存储和读取的顺序是一致的)B:有整数索引C:允许重复的 <!--more-->**List的特有功能**````voidadd(intindex,Eelement):将元素添加到index索引位置上Eget(intindex):根据index索引获取元素Eremove(intindex):根据index索引删除元素Es......