记录编号 | 188204 | 评测结果 | AAAAAAAAAA | ||
---|---|---|---|---|---|
题目名称 | [IOI 2001] 移动电话 | 最终得分 | 100 | ||
用户昵称 | 是否通过 | 通过 | |||
代码语言 | C++ | 运行时间 | 0.174 s | ||
提交时间 | 2015-09-21 23:04:28 | 内存使用 | 4.52 MiB | ||
#include<cstdio> #include<iostream> using namespace std; int S,L,B,R,T; int sum[1050][1050]; void set() { scanf("%d",&S); for(int i=1;i<=S;i++) for(int j=1;j<=S;j++) sum[i][j]=0; } int lowbit(int x) { return x&(-x); } void add() { int x,y,a; scanf("%d%d%d",&x,&y,&a);x++,y++; for(int i=x;i<=S;i+=lowbit(i)) for(int j=y;j<=S;j+=lowbit(j)) { sum[i][j]+=a; } } int getsum(int x,int y) { int re=0; for(int i=x;i>0;i-=lowbit(i)) for(int j=y;j>0;j-=lowbit(j)) { re+=sum[i][j]; } return re; } void print() { scanf("%d%d%d%d",&L,&B,&R,&T); L++,B++,R++,T++; int ans=getsum(R,T)-getsum(L-1,T)-getsum(R,B-1)+getsum(L-1,B-1); printf("%d\n",ans); } void read() { int a; while(true) { scanf("%d",&a); if(a==3) break; if(a==0) set(); if(a==1) add(); if(a==2) print(); } } int main() { freopen("mobilephones.in","r",stdin); freopen("mobilephones.out","w",stdout); read(); //print(); return 0; }