二次联通门 : LibreOJ「LibreOJ β Round #4」 游戏
/* LibreOJ「LibreOJ β Round #4」 游戏 找找规律就会发现。。 当有X的时候,答案跟X个数的奇偶有关 否则就求一下逆序对就好了。。 由于SB的错误。。WA了3发才过 然后就签完到走人了 */ #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #define Max 11 int key[Max * 10000], rank[Max * 10000]; int s[Max * 10000]; int Main () { int N, x; scanf ("%d", &N); register int i, j; static char l[Max]; int C = 0, cur = 0 ; bool f; if (N == 1) return printf ("L"), 0; for (i = 1; i <= N; ++ i) { scanf ("%s", l); f = false, x = 0; if (l[0] == ‘X‘) ++ C; else { int Len = strlen (l); if (l[0] == ‘-‘) { f = true; for (j = 1; j < Len; ++ j) if (isdigit (l[j])) x = x * 10 + l[j] - ‘0‘; } else { for (j = 0; j < Len; ++ j) if (isdigit (l[j])) x = x * 10 + l[j] - ‘0‘; } key[++ cur] = f ? -x : x; rank[cur] = key[cur]; } } if (C) return printf (C % 2 ? "W" : "L"), 0; long long Answer = 0; int Size; std :: sort (key + 1, key + 1 + cur); Size = std :: unique (key + 1, key + 1 + cur) - key - 1; for (i = 1; i <= cur; ++ i) { rank[i] = std :: lower_bound (key + 1, key + 1 + Size, rank[i]) - key; int res = 0; for (j = rank[i]; j <= cur; j += j & -j) ++ s[j]; for (j = rank[i]; j; j -= j & -j) res -= s[j]; for (j = cur; j; j -= j & -j) res += s[j]; Answer += res; } printf (Answer % 2 ? "W" : "L"); return 0; } int ZlycerQan = Main (); int main (int argc, char *argv[]) {;}
时间: 2024-10-12 22:52:24