Advertisement
Zeinab_Hamdy

Untitled

Jul 7th, 2023
1,226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.96 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define nl "\n"
  4. #define fi first
  5. #define se second
  6. #define pb push_back
  7. #define ll long long
  8. #define ull unsigned ll
  9. #define RV  return void
  10. #define inf 2000000000
  11. #define MOD ((ll) 1e9 + 7)
  12. #define sz(x) int(x.size())
  13. #define all(v) v.begin(), v.end()
  14. #define rall(v) v.rbegin(), v.rend()
  15. #define Mini(x) *min_element(all(x))
  16. #define Maxi(x) *max_element(all(x))
  17. #define fixed(n) fixed << setprecision(n)
  18. #define ceil(w, m) (((w) / (m)) + ((w) % (m) ? 1 : 0))
  19. #define cin(v) for (auto&i:v) cin >> i;
  20. #define cout(v) for (auto&i:v) cout << i << " ";
  21. #define clr(memo, x) memset(memo, x, sizeof memo)
  22. #define updmin(a, b) a = min(a, b)
  23. #define updmax(a, b) a = max(a, b)
  24. #define vi vector < int >
  25. #define vl vector < ll >
  26. #define vc vector < char >
  27. #define vs vector < string >
  28. #define v2i vector < vector < int > >
  29. #define v2l vector < vector < int > >
  30. #define seti set < int >
  31. #define setl set < ll >
  32. #define mapii map < int , int >
  33. #define mapll map < ll , ll >
  34. #define mapli map < ll , int >
  35. #define mapci map < char , int >
  36. #define mapsi map < string , int >
  37. #define pll pair < ll , ll >
  38. #define pii pair < int , int >
  39. #define range(l,r,x) for(int i=l ; i < r ; i+=x)
  40. #define FastCode ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  41. vector < string > ternary= {"NO\n" , "YES\n"};
  42.  
  43. void  Zainab(){
  44.             #ifndef ONLINE_JUDGE
  45.               freopen("input.txt", "r", stdin);  
  46.               freopen("output.txt", "w", stdout);
  47.             #endif
  48. }
  49.  
  50.  
  51. /*================================  Prblem solution  ================================ */
  52.  
  53. int dx[] ={ -1 , -1 , -1 , 1 , 1 , 1 , 0 , 0 };
  54. int dy[] ={0 , 1 , -1   , 0 , -1 , 1 , -1 , 1};
  55.  
  56.  
  57.  
  58. void myCode(){
  59.  
  60. int n , q;
  61. cin >> n >> q;
  62.  
  63. map < int , vector < pair < int , int > > > mp;
  64. vector < vector < bool > > vis(n+1 , vector < bool > (n+1 , 0));
  65. while(q--){
  66.     int l ,r , x;
  67.     cin >> l >> r >> x;
  68.     if(x){
  69.         vis[l][r]=1;
  70.         mp[x].pb({l,r});
  71.     }
  72.     else vis[l][r]=0;
  73.    
  74.    int cnt =0;
  75.    for(auto& [f,s] : mp){
  76.        for(auto& w : s) {
  77.            if(vis[w.fi][w.se]){
  78.                 cnt++;
  79.                 break;
  80.            }
  81.        }
  82.    }
  83.    if(cnt > 2 ) {
  84.        cout << "NO\n";
  85.        continue;
  86.    }
  87.    
  88.     bool enter=0;
  89.     for(auto& [f,s] : mp){
  90.         if(!sz(s)) continue;
  91.        
  92.         int l2 = s[0].fi , r2=s[0].se ;
  93.         for(auto& w : s){
  94.             if( vis[w.fi][w.se] and (abs(w.fi-l2) + abs(w.se - r2))%2){
  95.                 enter = 1;
  96.                 cout << "NO\n";
  97.                 break;
  98.             }
  99.         } if(enter) break;
  100.     }
  101.     if(enter) continue;
  102.    
  103.     cout << "YES\n";
  104. }
  105.  
  106.  
  107.  
  108. }
  109.  
  110.  
  111.  
  112. int main(){
  113.                                    FastCode ;
  114.                                     Zainab() ;
  115.  
  116.     int testCase=1;
  117.        //  cin >> testCase ;
  118.       for(int i=1 ; i<= testCase ; i++)
  119.         myCode();
  120.        
  121.     return 0;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement