社区讨论
一种P4514的解决方案
P4514上帝造题的七分钟参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mih0td8k
- 此快照首次捕获于
- 2025/11/27 13:56 3 个月前
- 此快照最后确认于
- 2025/11/27 14:02 3 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
#define int long long//你猜我为什么要加这一句
int pos[4][2049][2049],n,m;
int lowbit(int a){
return a&(-a);
}
char ch;
bool pd(int x,int y){
if(x>n || x<1 || y>m || y<1) return 1;
return 0;
}
void add(int x,int y,int delta){
if(pd(x,y)) return;
for(int i=x;i<=n;i+=lowbit(i)){
for(int j=y;j<=m;j+=lowbit(j)){
pos[0][i][j]+=delta;
pos[1][i][j]+=delta*x;
pos[2][i][j]+=delta*y;
pos[3][i][j]+=delta*x*y;
}
}
return;
}
int query(int x,int y){
int sum=0;
for(int i=x;i>0;i-=lowbit(i)){
for(int j=y;j>0;j-=lowbit(j)){
sum+=(x+1)*(y+1)*pos[0][i][j];
sum-=(y+1)*pos[1][i][j];
sum-=(x+1)*pos[2][i][j];
sum+=pos[3][i][j];
}
}
return sum;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>ch>>n>>m;
while(cin>>ch){
if(ch=='L'){
int a,b,c,d,delta;
cin>>a>>b>>c>>d>>delta;
add(a,b,delta);
add(a,d+1,-delta);
add(c+1,b,-delta);
add(c+1,d+1,delta);
}
else{
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<query(c,d)-query(a-1,d)-query(c,b-1)+query(a-1,b-1)<<'\n';
}
}
return 0;
}
//by wanghao_2012
回复
共 1 条回复,欢迎继续交流。
正在加载回复...