2018-icpc沈阳-G-思维
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记录下本次涉及到的点最后清零。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<stack>
#include<deque>
#include<bitset>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<cstdlib>
#include<ctype.h>
#include<ctime>
#include<functional>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define debug puts("debug")
#define mid ((L+R)>>1)
#define lc (id<<1)
#define rc (id<<1|1)
const int maxn=;
const int maxm=;
const double PI=acos(-1.0);
const double eps=1e-;
const LL mod=1e9+;
LL gcd(LL a,LL b){return b==?a:gcd(b,a%b);}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
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;}
struct Edge{int v,w,next;}; template<class T>
ostream & operator<<(ostream &out,vector<T>&v){
for(auto x:v)cout<<x<<' ';
return out;
}
void read(LL &n){
n=; char c=getchar();
while(c<''||c>'')c=getchar();
while(c>=''&&c<='') n=(n<<)+(n<<)+(c-''),c=getchar();
}
LL C[][];
LL dir[][]={,,,-,-,,-,-};
bool ojbk(LL x,LL y){
if(x<||x>||y<||y>||C[x][y]==)return ;
return ;
}
#define pll pair<LL,LL>
const LL MAX=+;
vector<pll> cl,a[MAX];
void AC(){
LL T,n,m,cas=;
scanf("%lld",&T);
while(T--){
scanf("%lld%lld",&n,&m);
LL last=;
LL x,y,w,k,op;
for(int i=;i<=n;++i){
scanf("%lld%lld%lld",&x,&y,&w);
cl.pb(mp(x,y));
C[x][y]+=w;
}
printf("Case #%lld:\n",++cas);
while(m--){
scanf("%lld%lld%lld",&op,&x,&y);
x=(x+last)%+;
y=(y+last)%+;cl.pb(mp(x,y));
if(op==){
scanf("%lld",&w);
C[x][y]=w; }
else if(op==){
C[x][y]=;
}
else if(op==){
scanf("%lld%lld",&k,&w);
set<pll>S;
for(auto v:a[k]){
for(int i=;i<;++i){
LL sx=x+v.fi*dir[i][],sy=y+v.se*dir[i][];
if(ojbk(sx,sy))S.insert(mp(sx,sy));
} }for(auto o:S){
C[o.fi][o.se]+=w;
}
}
else{
scanf("%lld",&k);
LL ans=;
set<pll>S;
for(auto v:a[k]){ for(int i=;i<;++i){
LL sx=x+v.fi*dir[i][],sy=y+v.se*dir[i][];
if(ojbk(sx,sy))S.insert(mp(sx,sy));
} }for(auto o:S){
ans+=C[o.fi][o.se];
}
printf("%lld\n",ans);
last=ans;
}
}
for(auto v:cl)C[v.fi][v.se]=;
cl.clear();
}
}
int main(){
for(LL i=;i<=;++i){
for(LL j=;j<=;++j){
if(i*i+j*j>MAX-)break;
a[i*i+j*j].pb(mp(i,j));
}
}
AC();
return ;
}
/* 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 */
2018-icpc沈阳-G-思维的更多相关文章
- 2018 ICPC 沈阳网络赛
2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...
- 2018 ICPC 沈阳网络预赛 Fantastic Graph (优先队列)
[传送门]https://nanti.jisuanke.com/t/31447 [题目大意]:有一个二分图,问能不能找到它的一个子图,使得这个子图中所有点的度数在区间[L,R]之内. [题解]首先我们 ...
- 2018 icpc 沈阳
https://codeforces.com/gym/101955 J 签到 #include<iostream> #include<cstring> #include< ...
- 2017 icpc 沈阳 G - Infinite Fraction Path
题目大意:有n个点, 每个点有一个数字0 - 9, 第 i 个点只能到 第(i * i + 1)个点,问你在哪个点出发走n次构成的数字串最大. 思路:利用求后缀数组的倍增比较思想, 许多细节需要注意. ...
- 2018 ICPC 沈阳网络赛预赛 Supreme Number(找规律)
[传送门]https://nanti.jisuanke.com/t/31452 [题目大意]:给定一个数字(最大可达10100),现在要求不超过它的最大超级质数.超级质数定义:对于一个数,把它看成数字 ...
- 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 ...
- 2018 ICPC 徐州网络赛
2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution ...
- [HDU6304][数学] Chiaki Sequence Revisited-杭电多校2018第一场G
[HDU6304][数学] Chiaki Sequence Revisited -杭电多校2018第一场G 题目描述 现在抛给你一个数列\(A\) \[ a_n=\begin{cases}1 & ...
- 2018 ICPC Asia Singapore Regional A. Largest Triangle (计算几何)
题目链接:Kattis - largesttriangle Description Given \(N\) points on a \(2\)-dimensional space, determine ...
- 2018 ICPC Pacific Northwest Regional Contest I-Inversions 题解
题目链接: 2018 ICPC Pacific Northwest Regional Contest - I-Inversions 题意 给出一个长度为\(n\)的序列,其中的数字介于0-k之间,为0 ...
随机推荐
- 两个有序数组的上中位数和第K小数问题
哈,再介绍个操蛋的问题.当然,网上有很多解答,但是能让你完全看懂的不多,即便它的结果是正确的,可是解释上也是有问题的. 所以,为了以示正听,我也做了分析和demo,只要你愿意学习,你就一定能学会,并且 ...
- C++内存分区:堆、栈、自由存储区、全局/静态存储区和常量存储区
日志 ...
- axf 文件包含太多的调试信息,导致的编译错误
构建工程时,提示: build\my_test_prj.axf: Error: L6291E: Cannot assign Fixed Execution Region MCU_FLASH1 Load ...
- mecacheq的配置
在处理业务逻辑时有可能遇到高并发问题,例如商城秒杀.微博评论等.如果不做任何措施可能在高瞬间造成服务器瘫痪,如何解决这个问题呢?队列是个不错的选择.队列(Queue)又称先进先出(First In F ...
- WebForm内置对象:Application和ViewState、Repeater的Command用法
一.内置对象 1.Application 存贮在服务器端,占用服务器内存生命周期:永久 所有人访问的都是这一个对象 传值:传的是object类型可以传对象. string s =TextBox1.Te ...
- js与jQuery的区别——每日一记录
js是一种脚本语言,jQuery是在他基础上的一种框架
- C#简单打印出LIST集合
循环打印集合,打印数组,随手写写,新手可以看看, 结果是不是有一些多余的0,把 int [][] ints =new int[3][]; 改为new int[2][]; 运行出错,哈哈. int ...
- 【javascript】script标签的async异步解析
<script src="script.js"></script> 没有 defer 或 async,浏览器会立即加载并执行指定的脚本,“立即”指的是在渲染 ...
- DelayQueue源码解析
DelayQueue是一个支持延时获取元素的无界阻塞队列.里面的元素全部都是“可延期”的元素,列头的元素是最先“到期”的元素,如果队列里面没有元素到期,是不能从列头获取元素的,哪怕有元素也不行.也就是 ...
- python学习笔记:装饰器2
python的装饰器本质是函数,为了不改变装饰目标函数内部代码而增加额外功能而存在 一.一般装饰函数实例: import datetime def func_name(func):#定义一个装饰函数, ...