fork download
  1. #pragma GCC optimize("Ofast")
  2. #pragma GCC target("avx,avx2,fma")
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. typedef long long int ll;
  6. int main(){
  7. ios_base::sync_with_stdio(false);
  8. cin.tie(0);cout.tie(0);
  9. int t;
  10. cin>>t;
  11. while(t--){
  12. ll n, i, j;
  13. cin >> n;
  14. vector<pair<ll,ll> > arr(n);
  15. pair<ll,ll> first, last;
  16. map<ll,map<ll,ll> > m1;
  17. for(i = 0; i < n; i++){
  18. cin >> arr[i].first >> arr[i].second;
  19. m1[arr[i].first][arr[i].second] = 1;
  20. if(arr[i].first == 1){
  21. first = {arr[i].first, arr[i].second};
  22. }
  23. else if(arr[i].second == n){
  24. last = {arr[i].first, arr[i].second};
  25. }
  26. }
  27. ll x, y;
  28. x = first.first; y = first.second;
  29. bool ok = false;
  30. while(y >= 1){
  31. if(m1[x][y] == 0){
  32. ok = true;
  33. break;
  34. }
  35. x += 1;
  36. y -= 1;
  37. }
  38. if(!ok){
  39. cout << "NO" << endl;
  40. continue;
  41. }
  42. x = last.first; y = last.second;
  43. while(x <= n){
  44. if(m1[x][y] == 0){
  45. ok = true;
  46. break;
  47. }
  48. x += 1;
  49. y -= 1;
  50. }
  51. if(!ok)
  52. cout << "NO" << endl;
  53. else
  54. cout << "YES" << endl;
  55. }
  56. return 0;
  57. }
  58.  
  59.  
Runtime error #stdin #stdout #stderr 0s 5624KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc