fork download
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<cmath>
  4. using namespace std;
  5. long long a[11005][11005],ans[11005];
  6. struct rect
  7. {
  8. long long x,y,w,h;
  9. };
  10. bool cmp(rect a, rect b)
  11. {
  12. return a.h*a.w>b.h*b.w;
  13. }
  14. int main()
  15. {
  16.  
  17. long long n,m;
  18. rect r[11005];
  19. cin>>n>>m;
  20. ans[0]=n*m;
  21. long long k;
  22. cin>>k;
  23. for(long long i=1;i<=k;i++)
  24. {
  25. cin>>r[i].x>>r[i].y>>r[i].w>>r[i].h;
  26. }
  27. sort(r+1,r+k+1,cmp);
  28. for(long long i=1;i<=k;i++)
  29. {
  30.  
  31.  
  32. int xx,yy;
  33. int flag=0;
  34. xx=r[i].x;
  35. yy=r[i].y;
  36. while(1)
  37. {
  38. if(a[xx][yy]!=0)
  39. {
  40.  
  41. if(r[a[xx][yy]].h>r[i].y-yy){ ans[a[r[i].x][yy]]=ans[a[r[i].x][yy]]-((r[i].h)*(r[i].w));flag=1; break;}
  42. }
  43. yy--;
  44. if(yy<0){break;}
  45. }
  46. ans[i]=(r[i].h)*(r[i].w);
  47. if(flag==0)ans[0]=ans[0]-((r[i].h)*(r[i].w));
  48. for(long long p=r[i].x;p<r[i].x+r[i].w;p++)
  49. {
  50.  
  51.  
  52. a[p][r[i].y]=i;
  53.  
  54. }
  55. }
  56. long long t;
  57. cin>>t;
  58.  
  59. for(long long i=1;i<=t;i++)
  60. {
  61. long long xx,yy,yys;
  62. cin>>xx>>yy;
  63. yys=yy;
  64. while(1)
  65. {
  66. if(a[xx][yy]!=0)
  67. {
  68. if(r[a[xx][yy]].h>yys-yy){cout<<ans[a[xx][yy]]<<endl;break;}
  69. }
  70. yy--;
  71. if(yy<0){cout<<ans[0]<<endl;break;}
  72. }
  73. }
  74. return 0;
  75. }
  76. // 11 7 3 2 1 5 5 8 2 2 3 3 2 3 2 4 4 3 3 5 10 1 9 3
  77.  
Success #stdin #stdout 0s 961536KB
stdin
Standard input is empty
stdout
Standard output is empty