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-思维的更多相关文章

  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. [js]js设计模式-单例模式

    单例模式 不同模块之间需要同时开发, // 单例模式: 把描述同一个事物的属性和方法放在同一个内存空间下. // 优点: 分组,防止冲突 // p1 p2也叫做命名空间(模块开发) var p1 = ...

  2. python列表常用内建方法

    python列表常用内建方法: abc = ['a',1,3,'a'] #abc.pop(1) #删除索引1的值.结果['a', 3] #abc.append([123]) #结果:['a', 1, ...

  3. How do you explain Machine Learning and Data Mining to non Computer Science people?

    How do you explain Machine Learning and Data Mining to non Computer Science people?   Pararth Shah, ...

  4. Software Testing 3

    Questions: • 7. Use the following method printPrimes() for questions a–d. 基于Junit及Eclemma(jacoco)实现一 ...

  5. K8S的网络接口CNI及灵雀云的实践

    K8S的网络模型 我们从底层网络来看,分为三个层面.首先是Pod之间的多个容器的网络互通.我们知道,K8S的Pod可以由多个容器组成,这个层面网络互通是比较简单的,因为所有的容器都是共享一个网卡,可以 ...

  6. SV coverage

    covergroup是对coverage model的一种包装,每个covergroup可以包含: 1) sync event来触发采样, 2) 很多coverpoint, 3) cross cove ...

  7. OpenStack-RabbitMQ-获取vm、磁盘、网络设备的状态变化

    需求 及时知道vm,硬盘,镜像,网络设备.负载均衡器状态变化 分析 Dashboard中也是通过定时使用ajax调用API来获取虚拟机的状态信息的定时轮训的方式过于被动 解决方案 共用rabbitmq ...

  8. Linux 配置SSH 无密钥登陆

    根据SSH 协议,每次登陆必须输入密码,比较麻烦,SSH还提供了公钥登陆,可以省去输入密码的步骤. 公钥登陆:用户将自己的公钥存储在远程主机上,登陆的时候,远程主机会向用户发送一串随机字符串,用户用自 ...

  9. Maven setting.xml文件详解(转)

    maven的配置文件settings.xml存在于两个地方: 1.安装的地方:${M2_HOME}/conf/settings.xml 2.用户的目录:${user.home}/.m2/setting ...

  10. bzoj2880

    打公式好麻烦 QAQ 为了节省时间去复习,原谅我引用一下别人的博客...http://blog.csdn.net/acdreamers/article/details/8542292 #include ...