Advertisement
VladSmirN

cpp

Oct 11th, 2020
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1.  long long m,n,q,x,y,k;
  2.         cin>>m>>n>>q;
  3.  
  4.         for(long long i = 0;i<q;++i){
  5.             cin>>x>>y>>k;
  6.             long long y1,x1,x2,sum;
  7.             sum = 0;
  8.             for(long long j =0;j<=k;++j){
  9.                 y1 = y + k - j;
  10.  
  11.                 x1 = max(x -  j,(long long)0);
  12.                 x2 = min(x + j, m);
  13.  
  14.  
  15.                 if(y1>n || y1<0) {
  16.                     continue;
  17.                 }
  18. //cout<<y1<<" "<<x1<<" "<<x2<<endl;
  19.                 sum += x2 - x1 +1;
  20.  
  21.             }
  22.  
  23.  
  24.             for(long long j =1;j<=k;++j){
  25.                 y1 = y - j;
  26.  
  27.                 x1 = max(x - k + j,(long long)0);
  28.                 x2 = min(x + k - j, m);
  29.  
  30.  
  31.                 if(y1>n || y1<0) {
  32.                     continue;
  33.                 }
  34.  
  35.                 sum += x2 - x1 +1;
  36. //cout<<y1<<" "<<x1<<" "<<x2<<endl;
  37.             }
  38.             cout<<sum<<endl;
  39.  
  40.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement