传送门:Best ACMer Solves the Hardest Problem


Best ACMer Solves the Hardest Problem Time limit12000 ms Memory limit1048576 kB

One day an excellent ACMer will leave the field to face new challenges, just like what the predecessors are doing. Some of them have taken over their family businesses, and some of them are struggling with the edges of unemployment. Some of them have the courage to display themselves and become a professional Ingress player, and some of them are still pushing themselves to limits and try to solve all problems in Project Euler.

But all these destinations are so shallow for Benecol de Cecco, the former king. What he does now is to be the best respondents in StackOverflow. StackOverflow is the largest, most trusted online community for developers to learn, share their programming knowledge, and build their careers.

Today, he notices a question which is posted by Kevin Li, saying: Recently, I implemented an experiment where I need to find all the data records whose Euclidean distances to the query point q are the same value r. I tried to use the k-d tree to improve the search efficiency. However, I found that the k-d tree needs to traverse all leaf nodes to return the result, that is, it still needs to compare all dataset to obtain the result.

This question can be formalized to build a database with real-time queries and modifications. In the beginning, suppose we have n different points in the plane. The i-th point is located at (xi,yi) and has a weight wi. Then we consider several queries and modifications dynamically given by

1 x y w, to insert a new point at (x,y) of weight w, where we guarantee that before the operation no point was located in the place;
2 x y, to delete the point located at (x,y), where we guarantee that the point existed before the operation;
3 x y k w, for each point whose Euclidean distance to (x,y) is √k, to increase its weight by w;
4 x y k, to query the sum of weights for all points whose Euclidean distances to (x,y) are √k.
Benecol de Cecco says this question is pretty easy and he asked me to share the problem with you all. By the way, the Euclidean distance between two points (x0,y0) and (x1,y1) is equal to sqrt((x0−x1)2+(y0−y1)2).

Input
The input contains several test cases, and the first line contains a positive integer T indicating the number of test cases which is up to 1000.

For each test case, the first line contains two integers n and m indicating the initial number of points in the plane and the number of operations respectively, where 1≤n,m≤105.

Each of the following n lines contains three integers x,y and w satisfying 1≤x,y,w≤6000, which describe a point at (x,y) of weight w in the beginning.

Each of the following m lines contains an operation which can be a query or a modification. These operations are given in the forms described above. To make all x and y in operations dynamic, we use lastans to denote the answer to the most recent query and its initial value is zero. For each operation with the values x and y in input, their real values should be (((x+lastans)mod6000)+1) and (((y+lastans)mod6000)+1) respectively. All coefficients in operations are integers and satisfy 0≤k≤107 and 1≤x,y,w≤6000.

We guarantee that the sum of n and the sum of m in all test cases are no larger than 106 individually.

Output
For each test case, output a line containing “Case #x:” (without quotes) at first, where x is the test case number starting from 1.

Then for each query, output an integer in a line indicating the answer.

Example
Input
1
3 6
2999 3000 1
3001 3000 1
3000 2999 1
1 2999 3000 1
4 2999 2999 1
2 2995 2996
3 2995 2995 1 1
4 2995 2995 1
4 3000 3000 1
Output
Case #1:
4
6
0
Note
In the sample case, if we ignore the special input format for dynamic x and y in operations, here we can show these modifications and queries directly in an offline format as follows:

1 3000 3001 1;
4 3000 3000 1;
2 3000 3001;
3 3000 3000 1 1;
4 3000 3000 1;
4 3007 3007 1.


打出1e7里每个数字可以有哪些(x,y),x2+y2等于这个数,然后每个点找距离根号k的点的时候,就四个方向找一下,用set存来去重(某个点某维坐标变成0的时候,会有重复的)

wa到吐,不注意的话很容易就超时和超内存

AC代码:


#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int N=1e7+10;
const int mod=6000;
int t,n,m;
int x,y,w,op,k;
int dir[4][2]={{1,1},{1,-1},{-1,1},{-1,-1}};
typedef pair<int,int> p1;
vector<p1 > g[N];
vector<p1 > cc;
set<pair<int,int> > st;
//set<pair<int,int> >::iterator its;
int mp[6100][6100];
//map<pair<int,int>,int> mp;void init()//预处理
{for(int a=0;a<=6000;a++){for(int b=0;b<=6000;b++){int k=a*a+b*b;if(k>1e7) break;g[k].push_back(make_pair(a,b));}}
}int main()
{init();scanf("%d",&t);int ca=0;while(t--){cc.clear();scanf("%d%d",&n,&m);printf("Case #%d:\n",++ca);for(int i=0;i<n;i++){scanf("%d%d%d",&x,&y,&w);mp[x][y]=w;cc.push_back(make_pair(x,y));}ll lastans=0;while(m--){scanf("%d%d%d",&op,&x,&y);x=(x+lastans)%mod+1;y=(y+lastans)%mod+1;if(op==1){scanf("%d",&w);mp[x][y]=w;cc.push_back(make_pair(x,y));}else if(op==2){mp[x][y]=0;}else if(op==3){st.clear();scanf("%d%d",&k,&w);int len=g[k].size();for(int i=0;i<len;i++){int dx=g[k][i].first,dy=g[k][i].second;for(int j=0;j<4;j++){int xx=x+dx*dir[j][0],yy=y+dy*dir[j][1];if(xx<1||xx>6000||yy<1||yy>6000)continue;if(mp[xx][yy]!=0){st.insert(make_pair(xx,yy));}}}set<pair<int,int> >::iterator its;for(its=st.begin();its!=st.end();its++){int xx=its->first,yy=its->second;mp[xx][yy]+=w;}}else if(op==4){st.clear();scanf("%d",&k);int len=g[k].size();ll sum=0;for(int i=0;i<len;i++){int dx=g[k][i].first,dy=g[k][i].second;for(int j=0;j<4;j++){int xx=x+dx*dir[j][0],yy=y+dy*dir[j][1];if(xx<1||xx>6000||yy<1||yy>6000)continue;if(mp[xx][yy]!=0){st.insert(make_pair(xx,yy));}}}set<pair<int,int> >::iterator its;for(its=st.begin();its!=st.end();its++){int xx=its->first,yy=its->second;sum+=mp[xx][yy];}lastans=sum;printf("%lld\n",sum);}}for(int i=0;i<cc.size();i++){mp[cc[i].first][cc[i].second]=0;}}return 0;
}

2018icpc沈阳站G题相关推荐

  1. ICPC2020 沈阳站 D题

    ICPC2020 沈阳站 D题 以 PiP_iPi​ 代表前iii个字符rrr出现的次数为奇数或偶数. 从iii到jjj区间如果对答案具有贡献,则pj−pi−1p_j-p_{i-1}pj​−pi−1​ ...

  2. 2021 ICPC 沈阳站 D题 Journey to Un‘Goro (打表+找规律)

    2021 ICPC 沈阳站 D.Journey to Un'Goro [链接][http://codeforces.com/gym/103202/problem/D](http://codeforce ...

  3. ZOJ 3987 Numbers 2017CCPC秦皇岛站G题 大整数 二进制 贪心

    题目:https://cn.vjudge.net/problem/ZOJ-3987 题意:给出一个数n(不超过4000个十进制数字),将其分成m(不超过10的100次方)个数,要求这m个数的和等于n. ...

  4. 【ICPC 2021 沈阳站】心路历程·总结分析

    ICPC 2021(沈阳)心路历程·总结分析 战果 前期准备 ①行程问题(时间留余) ②物资准备(板子.证件) ③饮食作息 热身赛 正式赛 战果 本次线下比赛打铁,与牌子挥之交臂,相处一年的阵容,最后 ...

  5. 2016ICPC沈阳站

    2016ICPC沈阳站 题号 题目 知识点 难度 A Thickest Burger 贪心 签到 B Relative atomic mass 贪心 签到 C Recursive sequence 矩 ...

  6. 2018 ICPC 沈阳站

    细胞色素训练3 排名:100/193 2018年ICPC沈阳站,学长在这里拿金了.听学长说开始时候很快的出了两题,排名第四,是可以进final的,然后一直没过题,直到最后封榜时候连过两题,金牌最后一名 ...

  7. 2021icpc亚洲赛区沈阳站总结

    2021icpc亚洲赛区沈阳站总结&&赛题复盘(打铁记) 个人感想 大学生涯的第一场acm,我也可能跟很多人一样吧,没打的时候踌躇满志,打完抑郁不堪.也很有幸,能跟许许多多耳熟能详的老 ...

  8. 21年icpc沈阳站记录

    icpc沈阳站记录 2021.11.22凌晨 从昨晚紧张到辗转反侧,虽然早就做好了打铁的心理准备,但待到比赛最后一刻两道铜牌题还没出时,满脑子的不甘心.当然最后肯定铁了395/576. 11.21也就 ...

  9. 2016ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)

    目录 A Thickest Burger B Relative atomic mass C Recursive sequence · 矩阵快速幂 E Counting Cliques · 暴力 H G ...

最新文章

  1. 【翻译】Ext JS 6 Beta发布
  2. 5G NGC — 会话管理模型 — PDU Session
  3. ML 02、监督学习
  4. python 3d绘图 拖动_使用python-matplotlib连续3D绘图(即图形更新)?
  5. rest接口_深度干货 | 测试REST服务接口
  6. c++ string 字符_C/C++知识分享:C++标准库之 string 类型,各种运算全部掌握
  7. 计组之指令系统:3、CISC和RISC
  8. python字典是什么的集合_Python中的字典和集合
  9. 小程序-调用公共js对象方法/ app.js
  10. 万万没想到 过去一年 蚂蚁森林成了联合国会议上的“网红”
  11. Seata多微服务互相调用_全局分布式事物使用案例_Account-Module 账户微服务说明---微服务升级_SpringCloud Alibaba工作笔记0064
  12. 大部分程序员还不知道的 Servelt3 异步请求,原来这么简单?
  13. 【python数据处理】替代Excel三维地图依据经纬度坐标的绘制热力地图的方式
  14. UNP编程:15---UDP之(recvfrom、sendto函数)
  15. android9 apk自动安装功能,Android自动安装APK
  16. 我来告诉你,一个草根程序员如何进入BAT
  17. 利用TLF给文本加样式
  18. 这10个免费学习网站,个个堪称神器,不收后悔!
  19. Go语言核心之美 1.4-包和文件
  20. 《分布式计算云计算与大数据》第一章

热门文章

  1. esper安装与示例
  2. latex设置字体加粗、斜体、下划线
  3. Allegro PCB Designer 17.2如何打开旧版本.brd文件
  4. 防火墙 Hillstone Networks SA-5050
  5. 经典题目——n阶幻方
  6. 电池PACK包高性价比设备检测方案
  7. 转行程序员日记--2020-08-24
  8. 相邻块(数细胞)问题之BFS解
  9. JS学习六(抽象工厂模式)
  10. 设置双核浏览器的浏览模式 meta name renderer content webkit|ie-comp|ie