Advertisement
a53

determinanta

a53
Dec 18th, 2021
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <fstream>
  2. #define zorro(x) ( (x ^ (x - 1)) & x )
  3. using namespace std;
  4. ifstream f("determinanta.in");
  5. ofstream g("determinanta.out");
  6. int n, i, j, ok, l, c;
  7. long long inv;
  8. int AIB[100003], lin[100003], col[100003], p[100003];
  9.  
  10. void Add(int x, int quantity)
  11. {
  12. int i;
  13.  
  14. for (i = x; i <= n; i += zorro(i))
  15. AIB[i] += quantity;
  16. }
  17.  
  18. int Compute(int x)
  19. {
  20. int i, ret = 0;
  21.  
  22. for (i = x; i > 0; i -= zorro(i))
  23. ret += AIB[i];
  24. return ret;
  25. }
  26.  
  27. int main()
  28. {
  29. f >> n;
  30. ok = 1;
  31. for(i = 1; i <= n; i++)
  32. {
  33. f >> l >> c;
  34. if(lin[l] == 1) ok = 0;
  35. if(col[c] == 1) ok = 0;
  36. lin[l] = 1;
  37. col[c] = 1;
  38. p[l] = c;
  39. }
  40. if(ok == 1)
  41. {
  42. inv = 0;
  43. for(j = 1; j <= n; j++)
  44. {
  45. inv += Compute(n)-Compute(p[j]);
  46. Add(p[j],1);
  47. }
  48. if(inv % 2 == 1) g << -1;
  49. else g << 1;
  50. }
  51. else
  52. {
  53. g << 0;
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement