记录编号 |
392489 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[NOI 2008] 糖果雨 |
最终得分 |
100 |
用户昵称 |
Marvolo |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
1.946 s |
提交时间 |
2017-04-07 21:15:33 |
内存使用 |
124.73 MiB |
显示代码纯文本
#pragma GCC optimize(3)
#include<cstdio>
#include<cstring>
#include<map>
#define N 1000
#define M 200001
using namespace std;
int len,k,T,cnt;
map <int,int> Map;
struct Cloud{
int x;
short l,r,d;
}cloud[M];
struct Bit_Array{
int n;
int a[N*4+1][N*4+1];
inline int bit(int x){return x&(-x);}
inline void Add(int x,int y,int val){
int i=0,j=0;
for (i=x+1;i<=n+5;i+=bit(i))
for (j=y+1;j<=n+5;j+=bit(j))
a[i-1][j-1]+=val;
}
inline int Query(int x,int y){
int i=0,j=0,ans=0;
for (i=x+1;i>0;i-=bit(i))
for (j=y+1;j>0;j-=bit(j))
ans+=a[i-1][j-1];
return ans;
}
inline int Query_Matrix(int x,int y,int p,int q){
return Query(p,q)-Query(p,y-1)-Query(x-1,q)+Query(x-1,y-1);
}
}bit,Bit;
inline void Add(int x,int y){
bit.Add(x,x+y,1); bit.Add(x+len*2,y+len*2+x,1);
Bit.Add(x,y+4*len-x,1); Bit.Add(x+len*2,y+2*len-x,1);
}
inline void Insert(){
int t=0,c=0,l=0,r=0,d=0,x=0,p=0;
scanf("%d%d%d%d%d",&t,&c,&l,&r,&d);
if (Map[c]==0) Map[c]=++cnt;
p=Map[c];
x=(d==1)?t-l:t+l;
x=(x%(2*len)+2*len)%(2*len);
cloud[p].x=x; cloud[p].l=l; cloud[p].r=r; cloud[p].d=d;
Add(cloud[p].x,r-l);
}
inline void Query(){
int t=0,l=0,r=0,x1=0,y1=0,x2=0,y2=0,ans=0;
scanf("%d%d%d",&t,&l,&r);
t%=(len*2);
x1=t; y1=l; x2=t+r; y2=len;
ans+=bit.Query_Matrix(x1,x1+y1,x2,x2+y2);
if (r!=0){
x1=2*len-r+t; y1=l-r; x2=2*len+t-1; y2=len+r;
y1+=len*4-x1; y2+=len*4-x2;
if (r==len) x1++;
ans+=Bit.Query_Matrix(x1,y1,x2,y2);
}
printf("%d\n",ans);
}
inline void Delete(){
int x=0,y=0,t=0,c=0,p=0;
scanf("%d%d",&t,&c);
p=Map[c];
x=cloud[p].x; y=cloud[p].r-cloud[p].l;
bit.Add(x,x+y,-1); bit.Add(x+len*2,y+len*2+x,-1);
Bit.Add(x,y+4*len-x,-1); Bit.Add(x+len*2,y+2*len-x,-1);
}
int main(){
freopen("noi2008_candy.in","r",stdin);
freopen("noi2008_candy.out","w",stdout);
scanf("%d%d",&T,&len);
bit.n=4*len+1; Bit.n=4*len+1;
while (T--){
scanf("%d",&k);
if (k==1) Insert(); else
if (k==2) Query(); else Delete();
}
return 0;
}