当前位置: 首页 > news >正文

I don‘t know

2074D - Counting Points

For some value of xx and a circle centered on (xi,0)(xi,0) with radius riri, we can find the range of yy where the points lie on using simple algebra.

y2≤r2i−(x−xi)2⟹−r2i−(x−xi)2−−−−−−−−−−−√≤y≤r2i−(x−xi)2−−−−−−−−−−−√y2≤ri2−(x−xi)2⟹−ri2−(x−xi)2≤y≤ri2−(x−xi)2

Here, we can see that when a=⌊r2i−(x−xi)2−−−−−−−−−−−√⌋a=⌊ri2−(x−xi)2⌋, there are 2a+12a+1 different integer values of yy in this range.

Now, think of how to deal with when multiple circles cover the same value of xx. This is not too hard; you can compute the value of aa for all of them and take the largest one. The rest can be ignored as the largest value of aa covers all of them.

The implementation is not hard; it simply boils down to using a std::map or some data structure to record the maximum value of aa for each value of xx that holds at least one point. The problem is solved in time complexity O(mlogm)O(mlog⁡m).

It is technically possible to solve the problem by fixing the value of yy instead of the value of xx, but it is significantly more tedious to implement.

Code

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
 
int main()
{
    int t;cin>>t;
    for(int i=0;i<t;i++)
    {
        int n,m;cin>>n>>m;
        map<ll,ll>cnt;
        auto isqrt=[&](ll x)
        {
            ll val=sqrtl(x)+5;
            while(val*val>x)val--;
            return val;
        };
        vector<ll>a(n),r(n);
        for(ll&i:a)cin>>i;
        for(ll&i:r)cin>>i;
        for(int i=0;i<n;i++)
        {
            ll aa=a[i],rr=r[i];
            for(ll x=aa-rr;x<=aa+rr;x++)
            {
                cnt[x]=max(cnt[x],2*isqrt(rr*rr-(x-aa)*(x-aa))+1);
            }
        }
        ll ans=0;
        for(auto[x,c]:cnt)ans+=c;
        cout<<ans<<"\n";
    }
}

相关文章:

  • 数据库分页查询详解
  • 嵌入式系统的核心组成部分处理器、存储器、传感器和执行器
  • 练习:倒着输出数字
  • 手机号登录与高并发思考
  • 《洛谷刷题笔记》day11
  • 如何使用AIOps明确Devps的问题归责
  • 【leetcode题解】二分算法
  • Spring6:8 资源操作-Resources
  • 排序算法总结
  • Spring的IOC
  • 回溯算法经典题目
  • 2025年03月18日柯莱特(外包宁德)一面前端面试
  • spring boot 拦截器
  • Spring Boot 集成 Elasticsearch怎样在不启动es的情况下正常启动服务
  • 什么是API❓
  • 语法: erase_program_eeprom(address)
  • NR SRS Configuration
  • C语言基础系列【27】typedef
  • AF3 quat_to_rot函数解读
  • 线性筛和欧拉函数
  • 丰田汽车:美国关税或导致4、5月损失1800亿日元,新财年净利润下滑三成
  • 国防部:正告菲方停止以任何方式冲撞中方核心利益
  • 驱逐行动再加码?特朗普或向利比亚和卢旺达遣送非法移民
  • 五一小长假上海“人从众”,全要素旅游交易总额超200亿元
  • 媒体:南京秦淮区卫健委回应一医院涉嫌违规提供试管婴儿服务
  • GOMU超马世锦赛,男女冠军刷新世界纪录