fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <bits/stdc++.h>
  6. #define ll long long
  7. using namespace std;
  8. void fastIO(void) {
  9. ios_base::sync_with_stdio(false);
  10. cin.tie(NULL);
  11. cout.tie(NULL);
  12. }
  13. ll rectangle[1000+1][1000+1]={(0,0)};
  14. ll PowerRect[11][1000+1][1000+1]={(0,0,0)};
  15. int main() {
  16. ll n,m; cin>>n>>m;
  17. for (ll i = 1; i<n+1; i++) {
  18. for (ll j = 1; j<m+1; j++) {
  19. cin>>rectangle[i][j];
  20. cout<<rectangle[i][j]<<' ';
  21. }
  22. }
  23. cout<<'\n';
  24. for (ll p = 1; p<=10; p++) {
  25. for (ll i = 1; i<n+1; i++) {
  26. for (ll j = 1; j<m+1; j++) {
  27. PowerRect[p][i][j]=p>rectangle[i][j];
  28. }
  29. }
  30. }
  31. for (ll p = 1; p<=10; p++) {
  32. for (ll i = 1; i<n+1; i++) {
  33. for (ll j = 1; j<m+1; j++) {
  34. PowerRect[p][i][j]=p>rectangle[i][j];
  35. cout<<PowerRect[p][i][j]<<' ';
  36. }
  37. cout<<'\n';
  38. }
  39. cout<<"\n\n\n";
  40. }
  41. for (ll p = 1; p<=10; p++) {
  42. for (ll i = 1; i<n+1; i++) {
  43. for (ll j = 1; j<m+1; j++) {
  44. PowerRect[p][i][j]+=PowerRect[p][i][j-1];
  45. }
  46. }
  47. for (ll i = 1; i<n+1; i++) {
  48. for (ll j = 1; j<m+1; j++) {
  49. PowerRect[p][i][j]+=PowerRect[p][i-1][j];
  50. }
  51. }
  52. }
  53. ll q; cin>>q;
  54. while (q--) {
  55. ll L1,U1,R1,D1,P1; cin>>L1>>U1>>R1>>D1>>P1;
  56. ll L2,U2,R2,D2,P2; cin>>L2>>U2>>R2>>D2>>P2;
  57. cout<<PowerRect[P1][D1][R1]<<' '<<PowerRect[P1][D1][L1-1]<<' '<<PowerRect[P1][U1-1][R1]<<' '<<PowerRect[P1][U1-1][L1-1]<<'\n';
  58. cout<<PowerRect[P2][D2][R2]<<' '<<PowerRect[P2][D2][L2-1]<<' '<<PowerRect[P2][U2-1][R2]<<' '<<PowerRect[P2][U2-1][L2-1]<<'\n';
  59. ll Mo7a = PowerRect[P1][D1][R1]-PowerRect[P1][D1][L1-1]-PowerRect[P1][U1-1][R1]+PowerRect[P1][U1-1][L1-1];
  60. ll Samo7a = PowerRect[P2][D2][R2]-PowerRect[P2][D2][L2-1]-PowerRect[P2][U2-1][R2]+PowerRect[P2][U2-1][L2-1];
  61. if (Mo7a == 0 && Samo7a == 0) {
  62. cout<<"Sameh"<<'\n';
  63. }
  64. else if (Mo7a>Samo7a) {
  65. cout<<"Mo7a"<<' '<<Mo7a<<'\n';
  66. }
  67. else if (Mo7a<Samo7a) {
  68. cout<<"Samo7a"<<' '<<Samo7a<<'\n';
  69. }
  70. else if (Mo7a==Samo7a) {
  71. cout<<"Draw"<<' '<<Samo7a<<'\n';
  72. }
  73.  
  74. }
  75. }
  76.  
Success #stdin #stdout 0.01s 26072KB
stdin
4 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
3
1 1 2 2 8
1 1 3 3 8
1 2 3 4 5
2 3 4 4 1
1 4 2 4 8
3 1 4 4 10
stdout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 
0 0 0 0 
0 0 0 0 
0 0 0 0 
0 0 0 0 



1 0 0 0 
0 0 0 0 
0 0 0 0 
0 0 0 0 



1 1 0 0 
0 0 0 0 
0 0 0 0 
0 0 0 0 



1 1 1 0 
0 0 0 0 
0 0 0 0 
0 0 0 0 



1 1 1 1 
0 0 0 0 
0 0 0 0 
0 0 0 0 



1 1 1 1 
1 0 0 0 
0 0 0 0 
0 0 0 0 



1 1 1 1 
1 1 0 0 
0 0 0 0 
0 0 0 0 



1 1 1 1 
1 1 1 0 
0 0 0 0 
0 0 0 0 



1 1 1 1 
1 1 1 1 
0 0 0 0 
0 0 0 0 



1 1 1 1 
1 1 1 1 
1 0 0 0 
0 0 0 0 



4 0 0 0
6 0 0 0
Samo7a 6
3 0 3 0
0 0 0 0
Sameh
4 0 4 0
9 5 0 0
Samo7a 4