3 条题解

  • 3
    @ 2021-8-7 18:39:46

    C++ :

    #include<bits/stdc++.h>
    #define ll long long
    #define inf 0x3f3f3f3f
    using namespace std;
    const int N=1e6+5;
    int n;
    ll a[N];
    int lowbit(int x)
    {
        return x&(-x);
    }
    void add(int x)
    {
        for (int i=x;i<=n;i+=lowbit(i))
        a[i]++;
    }
    ll sum(int x)
    {
       // cout<<x<<endl;
        ll s=0;
        for (int i=x;i>=1;i-=lowbit(i))
        s+=a[i];
        return s;
    }
    int main()
    {
        while(scanf("%d",&n)!=EOF)
        {
            n*=n;
            ll ans1=0,ans2=0;
            int x;
            memset(a,0,sizeof(a));
            for (int i=1;i<=n;i++)
            {
                scanf("%d",&x);
                if (x)
                {
                    ans1+=sum(n)-sum(x);
                    add(x);
                }
            }
            memset(a,0,sizeof(a));
            for (int i=1;i<=n;i++)
            {
                scanf("%d",&x);
                if (x)
                {
                    ans2+=sum(n)-sum(x);
                    add(x);
                }
            }
            if ((ans1%2)==(ans2%2)) printf("TAK\n"); else printf("NIE\n");
        }
        return 0;
    }
    
    • 0
      @ 2024-5-28 16:44:44
      #include<bits/stdc++.h>
      #define ll long long
      #define inf 0x3f3f3f3f
      using namespace std;
      const int N=1e6+5;
      int n;
      ll a[N];
      int lowbit(int x)
      {
          return x&(-x);
      }
      void add(int x)
      {
          for (int i=x;i<=n;i+=lowbit(i))
          a[i]++;
      }
      ll sum(int x)
      {
         // cout<<x<<endl;
          ll s=0;
          for (int i=x;i>=1;i-=lowbit(i))
          s+=a[i];
          return s;
      }
      int main()
      {
          while(scanf("%d",&n)!=EOF)
          {
              n*=n;
              ll ans1=0,ans2=0;
              int x;
              memset(a,0,sizeof(a));
              for (int i=1;i<=n;i++)
              {
                  scanf("%d",&x);
                  if (x)
                  {
                      ans1+=sum(n)-sum(x);
                      add(x);
                  }
              }
              memset(a,0,sizeof(a));
              for (int i=1;i<=n;i++)
              {
                  scanf("%d",&x);
                  if (x)
                  {
                      ans2+=sum(n)-sum(x);
                      add(x);
                  }
              }
              if ((ans1%2)==(ans2%2)) printf("TAK\n"); else printf("NIE\n");
          }
          return 0;
      }
      //钟鼎皓
      
      • 0
        @ 2022-10-15 19:45:30
        #include <cstring>
        #include <algorithm>
        
        using namespace std;
        
        typedef long long LL;
        const int N = 250000;
        int c[N], temp[N];
        
        LL merge_sort(int l, int r, int a[])
        {
            if(l >= r) return 0;
            int mid = l + r >> 1, i = l, j = mid + 1, k = 0;
            LL res = merge_sort(l, mid, a) + merge_sort(mid + 1, r, a);
            while(i <= mid && j <= r)
            {
                if(a[i] <= a[j]) temp[k++] = a[i++];
                else 
                {
                    res += mid - i + 1;
                    temp[k++] = a[j++];
                }
            }
            while(i <= mid) temp[k++] = a[i++];
            while(j <= r) temp[k++] = a[j++];
            for(int i = l, j = 0; i <= r; i++, j++) a[i] = temp[j];
            return res;
        }
        
        int main()
        {
            int n;
            while(cin >> n && n)
            {
                int a[N], b[N];
                for(int i = 0, j = 0; i < n * n; i++) 
                {
                    cin >> c[i];
                    if(c[i]) a[j++] = c[i];
                }
                for(int i = 0, j = 0; i < n * n; i++) 
                {
                    cin >> c[i];
                    if(c[i]) b[j++] = c[i];
                }
                LL res1 = merge_sort(0, n * n - 1, a);
                memset(temp, 0, sizeof temp);
                LL res2 = merge_sort(0, n * n - 1, b);
                memset(temp, 0, sizeof temp);
                if((res1 % 2) == (res2 % 2)) puts("TAK");
                else puts("NIE");
            }
            return 0;
        }
        
        
      • 1

      信息

      ID
      20
      时间
      1000ms
      内存
      128MiB
      难度
      1
      标签
      递交数
      118
      已通过
      86
      上传者