http://codeforces.com/gym/101955/problem/G

  给出一个6000*6000的坐标系,有四种操作,一是加入放置一个点到某个空格子上,二是从某个有点的格子移走一个点,三是将距离(x,y)距离为根号k的点权值加上w,四是询问距离(x,y)距离为根号k的点权值总和。

  由于k都是整数,而在圆上的整数点很少,所以想到,A^2+B^2=K^2,处理出所有(A,B)对于每个A^2+B^2。1,2操作就很简单了,3,4操作的话直接暴力从K对应的(A,B)暴力查找合法的点。

  各种TLE,WA,这个C数组大小6000*6000,每次都memset的话就会T,只能用一个vector记录下本次涉及到的点最后清零。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<map>
  5. #include<set>
  6. #include<stack>
  7. #include<deque>
  8. #include<bitset>
  9. #include<unordered_map>
  10. #include<unordered_set>
  11. #include<queue>
  12. #include<cstdlib>
  13. #include<ctype.h>
  14. #include<ctime>
  15. #include<functional>
  16. #include<algorithm>
  17. #include<bits/stdc++.h>
  18. using namespace std;
  19. #define LL long long
  20. #define pii pair<int,int>
  21. #define mp make_pair
  22. #define pb push_back
  23. #define fi first
  24. #define se second
  25. #define inf 0x3f3f3f3f
  26. #define debug puts("debug")
  27. #define mid ((L+R)>>1)
  28. #define lc (id<<1)
  29. #define rc (id<<1|1)
  30. const int maxn=;
  31. const int maxm=;
  32. const double PI=acos(-1.0);
  33. const double eps=1e-;
  34. const LL mod=1e9+;
  35. LL gcd(LL a,LL b){return b==?a:gcd(b,a%b);}
  36. LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
  37. LL qpow(LL a,LL b,LL c){LL r=; for(;b;b>>=,a=a*a%c)if(b&)r=r*a%c;return r;}
  38. struct Edge{int v,w,next;};
  39.  
  40. template<class T>
  41. ostream & operator<<(ostream &out,vector<T>&v){
  42. for(auto x:v)cout<<x<<' ';
  43. return out;
  44. }
  45. void read(LL &n){
  46. n=; char c=getchar();
  47. while(c<''||c>'')c=getchar();
  48. while(c>=''&&c<='') n=(n<<)+(n<<)+(c-''),c=getchar();
  49. }
  50. LL C[][];
  51. LL dir[][]={,,,-,-,,-,-};
  52. bool ojbk(LL x,LL y){
  53. if(x<||x>||y<||y>||C[x][y]==)return ;
  54. return ;
  55. }
  56. #define pll pair<LL,LL>
  57. const LL MAX=+;
  58. vector<pll> cl,a[MAX];
  59. void AC(){
  60. LL T,n,m,cas=;
  61. scanf("%lld",&T);
  62. while(T--){
  63. scanf("%lld%lld",&n,&m);
  64. LL last=;
  65. LL x,y,w,k,op;
  66. for(int i=;i<=n;++i){
  67. scanf("%lld%lld%lld",&x,&y,&w);
  68. cl.pb(mp(x,y));
  69. C[x][y]+=w;
  70. }
  71. printf("Case #%lld:\n",++cas);
  72. while(m--){
  73. scanf("%lld%lld%lld",&op,&x,&y);
  74. x=(x+last)%+;
  75. y=(y+last)%+;cl.pb(mp(x,y));
  76. if(op==){
  77. scanf("%lld",&w);
  78. C[x][y]=w;
  79.  
  80. }
  81. else if(op==){
  82. C[x][y]=;
  83. }
  84. else if(op==){
  85. scanf("%lld%lld",&k,&w);
  86. set<pll>S;
  87. for(auto v:a[k]){
  88. for(int i=;i<;++i){
  89. LL sx=x+v.fi*dir[i][],sy=y+v.se*dir[i][];
  90. if(ojbk(sx,sy))S.insert(mp(sx,sy));
  91. }
  92.  
  93. }for(auto o:S){
  94. C[o.fi][o.se]+=w;
  95. }
  96. }
  97. else{
  98. scanf("%lld",&k);
  99. LL ans=;
  100. set<pll>S;
  101. for(auto v:a[k]){
  102.  
  103. for(int i=;i<;++i){
  104. LL sx=x+v.fi*dir[i][],sy=y+v.se*dir[i][];
  105. if(ojbk(sx,sy))S.insert(mp(sx,sy));
  106. }
  107.  
  108. }for(auto o:S){
  109. ans+=C[o.fi][o.se];
  110. }
  111. printf("%lld\n",ans);
  112. last=ans;
  113. }
  114. }
  115. for(auto v:cl)C[v.fi][v.se]=;
  116. cl.clear();
  117. }
  118. }
  119. int main(){
  120. for(LL i=;i<=;++i){
  121. for(LL j=;j<=;++j){
  122. if(i*i+j*j>MAX-)break;
  123. a[i*i+j*j].pb(mp(i,j));
  124. }
  125. }
  126. AC();
  127. return ;
  128. }
  129. /*
  130.  
  131. 1
  132. 3 6
  133. 2999 3000 1
  134. 3001 3000 1
  135. 3000 2999 1
  136. 1 2999 3000 1
  137. 4 2999 2999 1
  138. 2 2995 2996
  139. 3 2995 2995 1 1
  140. 4 2995 2995 1
  141. 4 3000 3000 1
  142.  
  143. */

2018-icpc沈阳-G-思维的更多相关文章

  1. 2018 ICPC 沈阳网络赛

    2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...

  2. 2018 ICPC 沈阳网络预赛 Fantastic Graph (优先队列)

    [传送门]https://nanti.jisuanke.com/t/31447 [题目大意]:有一个二分图,问能不能找到它的一个子图,使得这个子图中所有点的度数在区间[L,R]之内. [题解]首先我们 ...

  3. 2018 icpc 沈阳

    https://codeforces.com/gym/101955 J 签到 #include<iostream> #include<cstring> #include< ...

  4. 2017 icpc 沈阳 G - Infinite Fraction Path

    题目大意:有n个点, 每个点有一个数字0 - 9, 第 i 个点只能到 第(i * i + 1)个点,问你在哪个点出发走n次构成的数字串最大. 思路:利用求后缀数组的倍增比较思想, 许多细节需要注意. ...

  5. 2018 ICPC 沈阳网络赛预赛 Supreme Number(找规律)

    [传送门]https://nanti.jisuanke.com/t/31452 [题目大意]:给定一个数字(最大可达10100),现在要求不超过它的最大超级质数.超级质数定义:对于一个数,把它看成数字 ...

  6. 2017 ACM/ICPC 沈阳 G题 Infinite Fraction Path

    The ant Welly now dedicates himself to urban infrastructure. He came to the kingdom of numbers and s ...

  7. 2018 ICPC 徐州网络赛

    2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution ...

  8. [HDU6304][数学] Chiaki Sequence Revisited-杭电多校2018第一场G

    [HDU6304][数学] Chiaki Sequence Revisited -杭电多校2018第一场G 题目描述 现在抛给你一个数列\(A\) \[ a_n=\begin{cases}1 & ...

  9. 2018 ICPC Asia Singapore Regional A. Largest Triangle (计算几何)

    题目链接:Kattis - largesttriangle Description Given \(N\) points on a \(2\)-dimensional space, determine ...

  10. 2018 ICPC Pacific Northwest Regional Contest I-Inversions 题解

    题目链接: 2018 ICPC Pacific Northwest Regional Contest - I-Inversions 题意 给出一个长度为\(n\)的序列,其中的数字介于0-k之间,为0 ...

随机推荐

  1. Bootstrap modal模态框关闭时,combobox input下拉框仍然保留在页面上

    问题描述: 当点击模态框的关闭按钮时,下拉框中的内容没有消失,而是移动到了页面左上角 分析:这个问题的定位在于是用的哪种模态框,bootstrap和easyui都可以实现模态框,但是两个方法实现的模态 ...

  2. Django组件——分页器和中间件

    分页器 Django内置分页器(paginator) 分页器函数为paginator,里面有几个重要的参数需要我们了解 paginator = Paginator(book_list, 10) #第二 ...

  3. python基础(16)-进程&线程&协程

    进程之multiprocessing模块 Process(进程) Process模块是一个创建进程的模块,借助这个模块,就可以完成进程的创建. 介绍 初始化参数 Process([group [, t ...

  4. ubuntu常用软件命令

    解压zip软件 unzip  xxx.zip -d解压到指定目录 清理磁盘空间 sudo apt-get autoremove sudo apt-get clean sudo dpkg --list ...

  5. cocos creator怎么隐藏组件(setVisible)

    以 label 为例: this.label.node.active = fasle 隐藏节点this.label.ndoe.active = true显示节点

  6. codeforces 982A Row

    题意: 一个01串是否合法满足以下两个要求: 1.没有两个相邻的1: 2.在满足第一个条件的情况下,不能再放下更多的1. 判断一个给定的串是否合法. 思路: 最近cf的A怎么都这么坑啊... 首先是判 ...

  7. 创建多线程的第一种方式——创建Thread子类和重写run方法

    创建多线程的第一种方式——创建Thread子类和重写run方法: 第二种方式——实现Runnable接口,实现类传参给父类Thread类构造方法创建线程: 第一种方式创建Thread子类和重写run方 ...

  8. java.lang.RuntimeException: wrong class format Caused by: org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException: null

    Spring Boot 启动的时候报的错 使用Drools 5.6版本,Spring Boot1.5.8版本,JAVA8版本,Eclipse4.4.2版本. Google后在Stack上发现一个,中文 ...

  9. P2472 [SCOI2007]蜥蜴(网络流)

    P2472 [SCOI2007]蜥蜴 把每个点拆成2个点,两点之间连边的边权为石柱高度 新建虚拟源点$S$和汇点$T$ $S$向所有有蜥蜴的点连边,边权1 其他边都连$inf$ 剩下就是裸的$dini ...

  10. Html from 标签

    Html from 标签 <html> <body> <!-- form 提交表单设置 --> <form> <input type=" ...