fork download
  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define int long long
  5. using namespace std;
  6. const long long oo=1e18;
  7. const int mod=1e9+7;
  8. const int base=31;
  9. int Test=1;
  10. bool bit(int mask,int i){return (mask>>i)&1;}
  11. void home()
  12. {
  13. if(fopen("main.inp","r"))
  14. freopen("main.inp","r",stdin),
  15. freopen("main.out","w",stdout);
  16. }
  17. int n,m,q,mu[100];
  18. map<pair<int,int>,int>mp;
  19. int Cal(int row,int c)
  20. {
  21. if(mp.count({row,c}))return mp[{row,c}];
  22. if(row==0)return c!=0;
  23. int x=upper_bound(mu,mu+35,row)-mu;
  24. int rem=c%mu[x];
  25. int len=mu[x-1];
  26. return mp[{row,c}]=(c/mu[x])*Cal(row-len,len)+Cal(row-len,min(rem,len));
  27. }
  28. int TinhLR(int row,int l,int r)
  29. {
  30. if(l==0)return Cal(row,r+1);
  31. int x=Cal(row,r+1)-Cal(row,l);
  32. if((row&l)==0&&(row&(l-1))==0)x++;
  33. return x;
  34. }
  35. void Tcmduc_VOI26()
  36. {
  37. cin>>n>>m>>q;
  38. mu[0]=1;for(int i=1;i<=40;i++)mu[i]=mu[i-1]*2;
  39. while(q--)
  40. {
  41. int x,y,u,v;cin>>x>>y>>u>>v;
  42. int so1=TinhLR(x,y,v),so2=TinhLR(y,x,u);
  43. if(!(x&y))so1--;
  44. cout<<so1+so2<<'\n';
  45. }
  46. }
  47. signed main()
  48. {
  49. ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);home();
  50. while(Test--)Tcmduc_VOI26();
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0s 5304KB
stdin
Standard input is empty
stdout
Standard output is empty