当前位置: 首页 > 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";
    }
}
http://www.dtcms.com/a/83485.html

相关文章:

  • 数据库分页查询详解
  • 嵌入式系统的核心组成部分处理器、存储器、传感器和执行器
  • 练习:倒着输出数字
  • 手机号登录与高并发思考
  • 《洛谷刷题笔记》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函数解读
  • 线性筛和欧拉函数
  • mysql实例2
  • AF3 rot_to_quat函数解读
  • 群体智能优化算法-蚁狮优化算法(Ant Lion Optimizer, ALO,含Matlab源代码)
  • 【愚公系列】《高效使用DeepSeek》024-儿童教育
  • 2025:sql注入详细介绍
  • 并发和并行、同步和异步、进程和线程的关系
  • 【MySQL篇】索引特性
  • pcap流量包分析
  • Linux 内核源码阅读——ipv4
  • 合成层优化