fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. #include <map>
  4. #include <utility>
  5. #include <algorithm>
  6. #include <ctime>
  7.  
  8. using namespace std;
  9.  
  10. const int N_MAX = 2507;
  11.  
  12. int n, m, q;
  13.  
  14. map<pair<pair<int,int>,pair<int,int> >,pair<unsigned long long,unsigned long long> > mp;
  15. pair<unsigned long long,unsigned long long> s[N_MAX][N_MAX];
  16.  
  17. void add(int x,int y,pair<unsigned long long,unsigned long long> del)
  18. {
  19. for (int kx = x; kx<=N_MAX-4; kx += kx&(-kx))
  20. for (int ky = y; ky <= N_MAX-4;ky += ky&(-ky))
  21. {
  22. s[kx][ky].first+=del.first;
  23. s[kx][ky].second+=del.second;
  24. }
  25. }
  26. pair<unsigned long long,unsigned long long> query(int x,int y)
  27. {
  28. pair<unsigned long long,unsigned long long> res=make_pair(0,0);
  29. for (int kx=x;kx;kx-=kx&(-kx))
  30. for (int ky=y;ky;ky-=ky&(-ky))
  31. {
  32. res.first+=s[kx][ky].first;
  33. res.second+=s[kx][ky].second;
  34. }
  35. return res;
  36. }
  37. int main()
  38. {
  39. scanf("%d%d%d",&n,&m,&q);
  40. memset(s,0,sizeof(s));
  41. srand(time(0));
  42. mp.clear();
  43. for (int i=1;i<=q;i++)
  44. {
  45. int t,r1,c1,r2,c2;
  46. scanf("%d%d%d%d%d",&t,&r1,&c1,&r2,&c2);
  47. pair<unsigned long long,unsigned long long> del,udel;
  48. if (t==1)
  49. {
  50. del.first=rand();
  51. del.second=rand();
  52. udel=make_pair(-del.first,-del.second);
  53. mp[make_pair(make_pair(r1,c1),make_pair(r2,c2))]=del;
  54. add(r1,c1,del);
  55. add(r1,c2+1,udel);
  56. add(r2+1,c1,udel);
  57. add(r2+1,c2+1,del);
  58. } else if (t==2)
  59. {
  60. del=mp[make_pair(make_pair(r1,c1),make_pair(r2,c2))];
  61. mp[make_pair(make_pair(r1,c1),make_pair(r2,c2))]=make_pair(0,0);
  62. udel=make_pair(-del.first,-del.second);
  63. add(r1,c1,udel);
  64. add(r1,c2+1,del);
  65. add(r2+1,c1,del);
  66. add(r2+1,c2+1,udel);
  67. }
  68. else
  69. {
  70. del=query(r1,c1);
  71. udel=query(r2,c2);
  72. if (del==udel) printf("Yes\n"); else printf("No\n");
  73. }
  74. }
  75. return 0;
  76. }
Success #stdin #stdout 0.03s 114240KB
stdin
2500 2500 8
1 549 1279 1263 2189
1 303 795 1888 2432
1 2227 622 2418 1161
3 771 2492 1335 1433
1 2017 2100 2408 2160
3 48 60 798 729
1 347 708 1868 792
3 1940 2080 377 1546
stdout
No
Yes
No