Advertisement
Ahmed_Negm

Untitled

Apr 22nd, 2023
1,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6. #define ll long long
  7. #define OO 2'000'000'000
  8. #define ull unsigned long long
  9. #define nl '\n'
  10. #define sz(x) (ll)(x.size())
  11. #define all(x) x.begin(),x.end()
  12. #define rall(s)  s.rbegin(), s.rend()
  13. #define getline(s) getline(cin>>ws,s)
  14. #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  15. #define pi  3.141592653589793
  16. #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  17. #define multi_ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
  18.  
  19.  
  20. void Fast_IO(){
  21. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  22. // freopen("filename.in", "r", stdin);
  23. // freopen("filename.txt", "w", stdout);
  24. #ifndef ONLINE_JUDGE
  25. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  26. #endif
  27. }
  28.  
  29.  
  30.  
  31.  
  32. int dx[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
  33. int dy[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
  34.  
  35.  
  36. bool good(int sz , vector<vector<int>>&pre){
  37.     int n = sz(pre),m = sz(pre[0]);
  38.     // minimum sum of size sz*sz
  39.     for(int i=1;i+sz-1<=n;i++){
  40.         for(int j=1;j+sz-1<=m;j++){
  41.             int sum = pre[i+sz-1][j+sz-1]-pre[i-1][j+sz-1]-pre[i+sz-1][j-1]+pre[i-1][j-1];
  42.             if(sum == 0) return true;
  43.         }
  44.     }
  45.     return false;
  46. }
  47.  
  48.  
  49.  
  50. void solve(){
  51. int n,m,q; cin>>n>>m>>q;
  52. vector<vector<int>>v(n+2,vector<int>(m+2));
  53.  
  54. auto fill =[&](int x1,int y1,int x2,int y2){
  55.     v[x2][y2]++,v[x2][y1-1]--;
  56.     v[x1-1][y2]--,v[x1-1][y1-1]++;
  57. };
  58.  
  59. auto build = [&](){
  60.     for(int i=n;i>=1;i--){
  61.         for(int j=m;j>=1;j--){
  62.             v[i][j] += v[i+1][j]+v[i][j+1]-v[i+1][j+1];
  63.         }
  64.     }
  65. };
  66.  
  67.  
  68. while(q--){
  69.     int x,y,k;
  70.     cin>>x>>y>>k;
  71.     int l = max(1,x-k),r = min(n,x+k);
  72.     int u = max(1,y-k),d = min(m,y+k);
  73.     fill(x,l,x,r);
  74.     fill(u,y,d,y);
  75. }
  76.  
  77. build();
  78.  
  79. for(int i=1;i<=n;i++){
  80.     for(int j=1;j<=m;j++){
  81.         v[i][j] = min(v[i][j],1);
  82.     }
  83. }
  84.  
  85. vector<vector<int>>pre = v;
  86.  
  87. for(int i=1;i<=n;i++){
  88.     for(int j=1;j<=m;j++){
  89.         pre[i][j] += pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1];
  90.     }
  91. }
  92.  
  93.  
  94. int l=1,r=min(n,m),ans=-1;
  95.  
  96. // while(l<=r){
  97. //     int mid = l+(r-l)/2;
  98. //     if(good(mid,pre)){
  99. //         ans = mid;
  100. //         l = mid+1;
  101. //     }else{
  102. //         r = mid-1;
  103. //     }
  104. // }
  105.  
  106. for(int i=1;i<=n;i++){
  107.     for(int j=1;j<=m;j++){
  108.         cout<<v[i][j]<<" ";
  109.     }
  110.     cout<<nl;
  111. }
  112.  
  113. if(ans == -1) cout<<-1<<nl;
  114. else cout<<ans*ans<<nl;
  115.  
  116.  
  117.  
  118.  
  119.  
  120. }
  121.  
  122. int main(){
  123.     Fast_IO();
  124. int t =1;
  125. //cin>>t;
  126. while(t--){
  127. solve();
  128. }
  129. return 0;
  130. }  
  131.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement