Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #define zorro(x) ( (x ^ (x - 1)) & x )
- using namespace std;
- ifstream f("determinanta.in");
- ofstream g("determinanta.out");
- int n, i, j, ok, l, c;
- long long inv;
- int AIB[100003], lin[100003], col[100003], p[100003];
- void Add(int x, int quantity)
- {
- int i;
- for (i = x; i <= n; i += zorro(i))
- AIB[i] += quantity;
- }
- int Compute(int x)
- {
- int i, ret = 0;
- for (i = x; i > 0; i -= zorro(i))
- ret += AIB[i];
- return ret;
- }
- int main()
- {
- f >> n;
- ok = 1;
- for(i = 1; i <= n; i++)
- {
- f >> l >> c;
- if(lin[l] == 1) ok = 0;
- if(col[c] == 1) ok = 0;
- lin[l] = 1;
- col[c] = 1;
- p[l] = c;
- }
- if(ok == 1)
- {
- inv = 0;
- for(j = 1; j <= n; j++)
- {
- inv += Compute(n)-Compute(p[j]);
- Add(p[j],1);
- }
- if(inv % 2 == 1) g << -1;
- else g << 1;
- }
- else
- {
- g << 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement