Advertisement
Alexandre_lsv

Untitled

Mar 17th, 2016
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.55 KB | None | 0 0
  1.     #include <bits/stdc++.h>
  2.     using namespace std;
  3.     typedef long long ll;
  4.     typedef long double ld;
  5.     int main(){
  6.         cin.sync_with_stdio(false);
  7.         cout.sync_with_stdio(false);
  8.         ll n, d;
  9.         char ch[501][501];
  10.         int mapp1[501][501] {};
  11.         int mapps1[501][501] {};
  12.         int mapp2[501][501] {};
  13.         int mapps2[501][501] {};
  14.  
  15.         cin >> n >> d;
  16.         for (int i=1; i<=n; i++)
  17.             for (int j=1; j<=d; j++)
  18.                 cin >> ch[i][j];
  19.         //map<pair<int, int>, int> mapp, mapps;
  20.         for (int i=1; i<=n; i++)
  21.             for (int j=1; j<=d; j++){
  22.                 if (i>1)
  23.                     if (ch[i][j]=='.' && ch[i-1][j]=='.' )
  24.                             mapp1[i][j]+=1;
  25.                     //mapp[i][j]+=mapp[i-1][j];
  26.                 //}
  27.  
  28.                 if (j>1)
  29.                         if (ch[i][j]=='.' && ch[i][j-1]=='.' )
  30.                             mapp2[i][j]+=1;
  31.                         //mapp[i][j]+=mapp[i][j-1];
  32.  
  33.                     //}
  34.             }
  35.         for (int i=1; i<=n; i++)
  36.             for (int j=1; j<=d; j++){
  37.                 for (int l=1; l<=i; l++){
  38.                     for (int k=1; k<=j; k++){
  39.                         mapps1[i][j]+=mapp1[l][k];
  40.                         mapps2[i][j]+=mapp2[l][k];
  41.                     }
  42.                 }
  43.             }
  44.  
  45.         ll k=0;
  46.         cin >> k;
  47.         /*cout << endl;
  48.         for (int i=1; i<=n; i++)
  49.         {
  50.             for (int j=1; j<=d; j++)
  51.                 cout << mapp1[i][j] << ' ';
  52.             cout << endl;
  53.         }
  54.         cout << endl;
  55.         for (int i=1; i<=n; i++)
  56.         {
  57.             for (int j=1; j<=d; j++)
  58.                 cout << mapps1[i][j] << ' ';
  59.             cout << endl;
  60.         }
  61.             cout << endl;
  62.         for (int i=1; i<=n; i++)
  63.         {
  64.             for (int j=1; j<=d; j++)
  65.                 cout << mapp2[i][j] << ' ';
  66.             cout << endl;
  67.         }
  68.         cout << endl;
  69.         for (int i=1; i<=n; i++)
  70.         {
  71.             for (int j=1; j<=d; j++)
  72.                 cout << mapps2[i][j] << ' ';
  73.             cout << endl;
  74.         }*/
  75.         for (int i=0; i<k; i++){
  76.             ll res=0;
  77.             ll r1, r2, c1, c2;
  78.             cin >> r1 >> c1 >> r2 >> c2;
  79.             res = mapps1[r2][c2]+mapps2[r2][c2]-mapps2[r2][c1]-mapps1[r1][c2]-mapps2[r1-1][c2]-mapps1[r2][c1-1]+mapps1[r1][c1-1]+mapps2[r1-1][c1];
  80.             //cout << mapps1[r2][c2] << ' ' << mapps1[r1][c2] << ' ' << mapps1[r2][c1-1] << ' ' << mapps1[r1][c1-1] << endl;
  81.             //cout << mapps2[r2][c2] << ' ' << mapps2[r1-1][c2] << ' ' << mapps2[r2][c1] << ' ' << mapps2[r1-1][c1] << endl;
  82.  
  83.             /*for (int j=c1; j<=c2; j++)
  84.                 res-=mapp2[r1][j];
  85.             for (int j=r1; j<=r2; j++)
  86.                 res-=mapp1[j][c1];
  87. */
  88.             //res-=mapp[r1][c1];
  89.             /*for (int j=r1; j<=r2; j++)
  90.                 res-=mapp[j][c1-1]*(r2-r1+1);
  91.             for (int l=c1; l<=c2; l++)
  92.                 res-=mapp[r1-1][l]*(r2-r1+1);
  93. */
  94.             /*for (int j=r1+1; j<=r2; j++){
  95.                 for (int l=c1+1; l<=c2; l++){
  96.                         res+=mapp[j][l];
  97.                         res+=mapps[j][l];
  98.                 }
  99.             }
  100.             for (int j=r1+1; j<=r2; j++)
  101.                     res+=mapp[j][c1];
  102.             for (int l=c1+1; l<=c2; l++)
  103.                     res+=mapps[r1][l];*/
  104.             cout << res << endl;
  105.         }
  106.         return 0;
  107.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement