7 条题解
-
5廖浩宇 LV 6 @ 2023-10-22 18:52:44
哪个逼那么不要脸抄我代码
点赞!!!
#include <bits/stdc++.h> using namespace std; long long a[1010][1010],ans[1010][1010]; int main() { int n,m,k,t; cin>>n>>m>>k>>t; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { scanf("%lld",&a[i][j]); ans[i][j]=a[i][j]-a[i-1][j]-a[i][j-1]+a[i-1][j-1]; } while(k--) { long x1,x2,y1,y2,num; scanf("%lld%lld%lld%lld%lld",&x1,&y1,&x2,&y2,&num); ans[x2+1][y2+1]+=num; ans[x1][y1]+=num; ans[x1][y2+1]-=num; ans[x2+1][y1]-=num; } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { ans[i][j]+=ans[i][j-1]+ans[i-1][j]-ans[i-1][j-1]; printf("%lld ",ans[i][j]); } printf("\n"); } for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) ans[i][j]+=ans[i][j-1]+ans[i-1][j]-ans[i-1][j-1]; while(t--) { int x1,x2,y1,y2; scanf("%lld%lld%lld%lld",&x1 ,&y1,&x2,&y2); printf("%lld\n",ans[x2][y2]-ans[x1-1][y2]-ans[x2][y1-1]+ans[x1-1][y1-1]); } return 0; }
哪个逼那么不要脸抄我代码
点赞!!!
-
22023-4-30 21:22:54@
终于,终于(激动),终于做出来辣!!!!!!!!!!!!!!!!!!!!! 真的太复杂啦:
ll x1,y1,x2,y2,c; while(p--){ scanf("%lld %lld %lld %lld %lld",&x1,&y1,&x2,&y2,&c); b[x1][y1]+=c;//利用差分快速加法 b[x1][y2+1]-=c; b[x2+1][y1]-=c; b[x2+1][y2+1]+=c; } for(int i=1;i<=n;i++){//构造加法后的a数组 for(int j=1;j<=m;j++){ b[i][j]+=b[i-1][j]+b[i][j-1]-b[i-1][j-1]; printf("%lld ",b[i][j]); } printf("\n"); } for(int i=1;i<=n;i++)//再构造a的前缀和数组 for(int j=1;j<=m;j++)b[i][j]+=b[i-1][j]+b[i][j-1]-b[i-1][j-1]; while(q--){ scanf("%lld %lld %lld %lld",&x1,&y1,&x2,&y2); ll sum=b[x2][y2]-b[x1-1][y2]-b[x2][y1-1]+b[x1-1][y1-1];//利用前缀和输出 printf("%lld\n",sum); } return 0; }
-
12023-10-29 17:40:11@
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 10; const int INF = 0x3f3f3f3f; long long n , m , p , q , x , y , x2 , y2 , z; long long cf[N][N] , a[N][N] , s[N][N]; int main() { cin >> n >> m >> p >> q; for( int i = 1 ; i <= n ; i++ ) { for( int j = 1 ; j <= m ; j++ ) { cin >> a[i][j]; cf[i][j] = a[i][j] - a[i-1][j] - a[i][j-1] + a[i-1][j-1]; } } while( p-- ) { cin >> x >> y >> x2 >> y2 >> z; cf[x][y] += z; cf[x][y2+1] -= z; cf[x2+1][y] -= z; cf[x2+1][y2+1] += z; } for( int i = 1 ; i <= n ; i++ ) { for( int j = 1 ; j <= m ; j++ ) { a[i][j] = a[i-1][j] + a[i][j-1] - a[i-1][j-1] + cf[i][j]; s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + a[i][j]; cout << a[i][j] << " "; } cout << endl; } while( q-- ) { cin >> x >> y >> x2 >> y2; cout << s[x2][y2] - s[x-1][y2] - s[x2][y-1] + s[x-1][y-1] << endl; } return 0; }
-
02024-10-29 17:09:32@
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 10; const int INF = 0x3f3f3f3f; long long n , m , p , q , x , y , x2 , y2 , z; long long cf[N][N] , a[N][N] , s[N][N]; int main() { cin >> n >> m >> p >> q; for( int i = 1 ; i <= n ; i++ ) { for( int j = 1 ; j <= m ; j++ ) { cin >> a[i][j]; cf[i][j] = a[i][j] - a[i-1][j] - a[i][j-1] + a[i-1][j-1]; } } while( p-- ) { cin >> x >> y >> x2 >> y2 >> z; cf[x][y] += z; cf[x][y2+1] -= z; cf[x2+1][y] -= z; cf[x2+1][y2+1] += z; } for( int i = 1 ; i <= n ; i++ ) { for( int j = 1 ; j <= m ; j++ ) { a[i][j] = a[i-1][j] + a[i][j-1] - a[i-1][j-1] + cf[i][j]; s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + a[i][j]; cout << a[i][j] << " "; } cout << endl; } while( q-- ) { cin >> x >> y >> x2 >> y2; cout << s[x2][y2] - s[x-1][y2] - s[x2][y-1] + s[x-1][y-1] << endl; } return 0; } 小鸟专属
-
02023-10-22 20:30:35@
#include <bits/stdc++.h> using namespace std; const int N=1e3+10;
long long n,m,p,q,cf[N][N],a[N][N],s[N][N]; long long x,y,x2,y2,z;
int main(){ cin>>n>>m>>p>>q; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>a[i][j]; cf[i][j]=a[i][j]-a[i][j-1]+a[i-1][j-1]; } }
while(p--){ cin>>x>>y>>x2>>y2>>z; cf[x][y]+=z; cf[x][y2+1]-=z; cf[x2+1][y]-=z; cf[x2+1][y2+1]+=z; } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ a[i][j]=a[i-1][j]+a[i][j-1]-a[i-1][j-1]+cf[i][j]; s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i][j]; cout<<a[i][j]<<" "; } cout<<endl; } while(q--){ cin>>x>>y>>x2>>y2; cout<<s[x2][y2]-s[x-1][y2]-s[x2][y-1]+s[x-1][y-1]<<endl; } return 0;
}
-
02023-10-11 20:31:04@
#include<iostream> #include<cmath> #include<string> #include<iomanip> using namespace std; const int N = 1e3 + 10; long long n , m , p , q , a[N][N] , s[N][N] , x , y , x2 , y2 , cf[N][N] , tmp; int main(){ cin >> n >> m >> q; for(int i = 1;i <= n;i++) { for(int j = 1; j <= m;j++) { cin >> a[i][j]; cf[i][j] = a[i][j] - a[i-1][j] - a[i][j-1] + a[i-1][j-1]; } }
while(p--) { cin >> x >> y >> x2 >> y2; cout << sum[x2][y2] - sum[x-1][y2] - sum[x2][y-1] + sum[x-1][y-1] << endl; } return 0;
}保存一下代码哈,晚点再发真代码
-
02023-4-30 16:54:41@
#include<bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; long long a[1010][1010],ans[1010][1010]; int main() { int n,m,k,t; cin>>n>>m>>k>>t; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { scanf("%lld",&a[i][j]); ans[i][j]=a[i][j]-a[i-1][j]-a[i][j-1]+a[i-1][j-1]; } while(k--) { long long x1,x2,y1,y2,num; scanf("%lld%lld%lld%lld%lld",&x1,&y1,&x2,&y2,&num); ans[x2+1][y2+1]+=num; ans[x1][y1]+=num; ans[x1][y2+1]-=num; ans[x2+1][y1]-=num; } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { ans[i][j]+=ans[i][j-1]+ans[i-1][j]-ans[i-1][j-1]; printf("%lld ",ans[i][j]); } printf("\n"); } for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) ans[i][j]+=ans[i][j-1]+ans[i-1][j]-ans[i-1][j-1]; while(t--) { int x1,x2,y1,y2; scanf("%lld%lld%lld%lld",&x1 ,&y1,&x2,&y2); printf("%lld\n",ans[x2][y2]-ans[x1-1][y2]-ans[x2][y1-1]+ans[x1-1][y1-1]); } return 0; }
- 1
信息
- ID
- 1285
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- 递交数
- 667
- 已通过
- 134
- 上传者