标签:一个 bubuko 分时 struct log flag erro 额外 error
# include <bits/stdc++.h>
using namespace std;
namespace Base{
# define mr make_pair
typedef long long ll;
typedef double db;
const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
const ll infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
template<typename T> void read(T &x){
x = 0; int fh = 1; double num = 1.0; char ch = getchar();
while (!isdigit(ch)){ if (ch == '-') fh = -1; ch = getchar(); }
while (isdigit(ch)){ x = x * 10 + ch - '0'; ch = getchar(); }
if (ch == '.'){
ch = getchar();
while (isdigit(ch)){num /= 10; x = x + num * (ch - '0'); ch = getchar();}
}
x = x * fh;
}
template<typename T> void chmax(T &x, T y){x = x < y ? y : x;}
template<typename T> void chmin(T &x, T y){x = x > y ? y : x;}
}
using namespace Base;
const int K = 110;
struct Point{
int x, y;
}p[K], t[K], a[K], b[K];
int k, n, mu[K], flag;
void check(){
int lim = (1 << k);
ll sum = 0;
for (int i = 1; i < lim; i++){
int num = 0;
int ax = 0, ay = 0, bx = n - 1, by = n - 1;
for (int j = 1; j <= k; j++)
if ((i & (1 << (j - 1))) != 0){
num++;
ax = max(a[j].x, ax);
ay = max(a[j].y, ay);
bx = min(b[j].x, bx);
by = min(b[j].y, by);
}
if (ax <= bx && ay <= by)
sum = sum + mu[num] * 1ll * (bx - ax) * (by - ay);
}
if (sum == 1ll * (n - 1) * (n - 1)) flag = true;
}
void dfs(int x){
if (x > k){
check();
return;
}
for (int i = 0; i < 4; i++){
a[x].x = min(p[x].x, t[i].x);
a[x].y = min(p[x].y, t[i].y);
b[x].x = max(p[x].x, t[i].x);
b[x].y = max(p[x].y, t[i].y);
dfs(x + 1);
}
}
int main(){
freopen("lighting.in", "r", stdin);
freopen("lighting.out", "w", stdout);
mu[0] = -1;
for (int i = 1; i < K; i++) mu[i] = mu[i - 1] * (-1);
int op; read(op);
while (op--){
read(k); read(n);
for (int i = 1; i <= k; i++)
read(p[i].x), read(p[i].y);
flag = false;
if (k > 4) {
printf("yes\n");
continue;
}
t[0].x = 0, t[0].y = 0;
t[1].x = n - 1, t[1].y = 0;
t[2].x = 0, t[2].y = n - 1;
t[3].x = n - 1, t[3].y = n - 1;
dfs(1);
if (flag == true)
printf("yes\n");
else printf("no\n");
}
return 0;
}
# include <bits/stdc++.h>
namespace Base{
# define mr make_pair
typedef long long ll;
typedef double db;
const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
const ll infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
template<typename T> void read(T &x){
x = 0; int fh = 1; double num = 1.0; char ch = getchar();
while (!isdigit(ch)){ if (ch == '-') fh = -1; ch = getchar(); }
while (isdigit(ch)){ x = x * 10 + ch - '0'; ch = getchar(); }
if (ch == '.'){
ch = getchar();
while (isdigit(ch)){num /= 10; x = x + num * (ch - '0'); ch = getchar();}
}
x = x * fh;
}
template<typename T> void chmax(T &x, T y){x = x < y ? y : x;}
template<typename T> void chmin(T &x, T y){x = x > y ? y : x;}
}
using namespace Base;
const int N = 300010, P = 998244353;
struct INT{
int n[N], len;
void GetFromSt(char *st){
len = strlen(st);
for (int i = 0; i < len; i++) n[i] = st[len - i - 1] - '0';
}
}num[4], tmp;
bool operator >=(INT &x, INT &y){
if (x.len > y.len) return true;
if (x.len < y.len) return false;
for (int i = x.len - 1; i >= 0; i--){
if (x.n[i] > y.n[i]) return true;
if (x.n[i] < y.n[i]) return false;
}
return true;
}
INT operator -(INT a, INT &b){
for (int i = 0; i < a.len; i++)
a.n[i] -= b.n[i];
for (int i = 0; i < a.len; i++)
if (a.n[i] < 0) a.n[i] += 10, a.n[i + 1] -= 1;
while (a.len > 0 && a.n[a.len - 1] == 0) a.len--;
return a;
}
int n, op;
const int to[] = {-1, 0, 2, 1, 4, 5, 3, -1};
ll h[N][3], mul[N];
int rk[N][3], tnp[3];
char st[N], mp[3], l[N], r[N];
void error(){
printf("-1\n");
exit(0);
}
void solve(int id, int now, int tag){
if (id == 0){
printf("%c", mp[now]);
return;
}
int nowl = now, nowr = (now + 1) % 3;
if (rk[id - 1][nowl] > rk[id - 1][nowr]) std::swap(nowl, nowr);
if ((tag & 1) != 0){
if (r[id] == '0' && (tag & 2) == 0)
solve(id - 1, nowl, 1);
else solve(id - 1, nowl, 3);
}
else {
if (l[id] == '0'){
if (r[id] == '0' && (tag & 2) == 0)
solve(id - 1, nowl, 0);
else solve(id - 1, nowl, 2);
}
}
if ((tag & 2) != 0){
if (l[id] == '1' && (tag & 1) == 0)
solve(id - 1, nowr, 2);
else solve(id - 1, nowr, 3);
}
else {
if (r[id] == '1'){
if (l[id] == '1' && (tag & 1) == 0)
solve(id - 1, nowr, 0);
else solve(id - 1, nowr, 1);
}
}
}
int main(){
freopen("rsp.in", "r", stdin);
freopen("rsp.out", "w", stdout);
read(n); read(op);
scanf("\n%s", st); num[1].GetFromSt(st);
scanf("\n%s", st); num[2].GetFromSt(st);
scanf("\n%s", st); num[0].GetFromSt(st);
num[3] = num[0]; tmp.len = 1; tmp.n[0] = 2;
if (num[3] >= num[1]) num[3] = num[1];
if (num[3] >= num[2]) num[3] = num[2];
num[0] = num[0] - num[3]; if (num[0] >= tmp) error();
num[1] = num[1] - num[3]; if (num[1] >= tmp) error();
num[2] = num[2] - num[3]; if (num[2] >= tmp) error();
int tag = (num[0].n[0]) + (num[1].n[0] << 1) + (num[2].n[0] << 2);
tag = to[tag];
tag = ((tag - n) % 6 + 6) % 6;
tag = tag / 2;
rk[0][0] = 0, rk[0][1] = 1, rk[0][2] = 2;
h[0][0] = 'P', h[0][1] = 'R', h[0][2] = 'S'; mul[0] = 233;
for (int i = 1; i <= n; i++){
mul[i] = mul[i - 1] * mul[i - 1] % P;
rk[i][0] = std::min(rk[i - 1][0], rk[i - 1][1]) * 3 + std::max(rk[i - 1][0], rk[i - 1][1]);
rk[i][1] = std::min(rk[i - 1][1], rk[i - 1][2]) * 3 + std::max(rk[i - 1][1], rk[i - 1][2]);
rk[i][2] = std::min(rk[i - 1][2], rk[i - 1][0]) * 3 + std::max(rk[i - 1][2], rk[i - 1][0]);
for (int j = 0; j < 3; j++) tnp[j] = (rk[i][j] > rk[i][0]) + (rk[i][j] > rk[i][1]) + (rk[i][j] > rk[i][2]);
for (int j = 0; j < 3; j++){
rk[i][j] = tnp[j];
if (rk[i - 1][j] < rk[i - 1][(j + 1) % 3])
h[i][j] = (h[i - 1][j] + h[i - 1][(j + 1) % 3] * mul[i - 1]) % P;
else h[i][j] = (h[i - 1][(j + 1) % 3] + h[i - 1][j] * mul[i - 1]) % P;
}
}
if (op != 2) printf("%lld\n", h[n][tag]);
if (op == 1) exit(0);
scanf("\n%s", l + 1);
for (int i = 1; i <= n / 2; i++) std::swap(l[i], l[n - i + 1]);
scanf("\n%s", r + 1);
for (int i = 1; i <= n / 2; i++) std::swap(r[i], r[n - i + 1]);
mp[0] = 'P', mp[1] = 'R', mp[2] = 'S';
solve(n, tag, 0);
printf("\n");
return 0;
}
考虑进一步拓展,形式无非就f1f1f1f1,f2f2,f3f1,f2f1f1,f4这几种情况,剩下的问题就是配容斥系数,因为k只有4容斥系数可以手算出来。最终答案是:
Ans=(f1f1f1f1+8f3f1+3f2f2-6f2f1f1-6f4)/24
# include <bits/stdc++.h>
# define ll long long
using namespace std;
const int T = 100001, N = 600001;
ll ans[N];
int read(){
int tmp=0, fh=1; char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') fh=-1; ch=getchar();}
while (ch>='0'&&ch<='9'){tmp=tmp*10+ch-'0'; ch=getchar();}
return tmp*fh;
}
namespace Transform{
const int P = 998244353, G = 3;
int power(int x, int y){
int i = x; x = 1;
while (y > 0){
if (y % 2 == 1) x = 1ll * i * x % P;
i = 1ll * i * i % P;
y /= 2;
}
return x;
}
void NTT(int *a, int l, int tag){
for (int i = 0, j = 0; i < l; i++){
if (i > j) swap(a[i], a[j]);
for (int k = (l >> 1); (j ^= k) < k; k >>= 1);
}
for (int i = 1; i < l; i <<= 1){
int wn = power(G, (P - 1) / (i * 2));
if (tag == -1) wn = power(wn, P - 2);
for (int j = 0; j < l; j += i + i){
int w = 1;
for (int k = 0; k < i; k++, w = 1ll * w * wn % P){
int x = a[k + j], y = 1ll * w * a[k + j + i] % P;
a[k + j] = (x + y) % P, a[k + j + i] = (x - y + P) % P;
}
}
}
if (tag == -1){
int in = power(l, P - 2);
for (int i = 0; i < l; i++) a[i] = 1ll * a[i] * in % P;
}
}
}
using namespace Transform;
int num1[N], num2[N], num3[N], num4[N], now1[N], now2[N], now3[N], now4[N], len, nn, n, m, k;
void print(){
int sum = 0;
for (int i = 0; i < N; i++)
sum = sum ^ (1ll * ans[i] * i % P);
printf("%d\n", sum);
}
int main(){
freopen("energy.in","r",stdin);
freopen("energy.out","w",stdout);
int inv2 = power(2, P - 2), inv6 = power(6, P - 2), inv24 = power(24, P - 2);
n = read(), k = read();
for (int i = 1; i <= n; i++) num1[read()]++;
for (int i = 1; i <= T; i++) num2[i * 2]= num1[i], num3[i * 3] = num1[i], num4[i * 4] = num1[i];
len = T * 4 + 1;
nn = 1; while (nn < len) nn <<= 1;
if (k == 1){
for (int i = 0; i < nn; i++) ans[i] = num1[i];
print();
return 0;
}
if (k == 2){
NTT(num1, nn, 1);
for (int i = 0; i < nn; i++) now1[i] = 1ll * num1[i] * num1[i] % P;
NTT(now1, nn, -1);
for (int i = 0; i < nn; i++) ans[i] = 1ll * (now1[i] - num2[i] + P) * inv2 % P;
print();
return 0;
}
if (k == 3){
NTT(num1, nn, 1); NTT(num2, nn, 1);
for (int i = 0; i < nn; i++) now2[i] = 1ll * num2[i] * num1[i] % P;
NTT(now2, nn, -1);
for (int i = 0; i < nn; i++) now1[i] = 1ll * num1[i] * num1[i] % P * num1[i] % P;
NTT(now1, nn, -1);
for (int i = 0; i < nn; i++) ans[i] = (1ll * (now1[i] - 3ll * now2[i] + 2ll * num3[i]) % P * inv6 % P + P) % P;
print();
return 0;
}
if (k == 4){
NTT(num1, nn, 1); NTT(num2, nn, 1); NTT(num3, nn, 1);
for (int i = 0; i < nn; i++) now1[i] = 1ll * num1[i] * num1[i] % P * num1[i] % P * num1[i] % P;
NTT(now1, nn, -1);
for (int i = 0; i < nn; i++) now2[i] = 1ll * num3[i] * num1[i] % P;
NTT(now2, nn, -1);
for (int i = 0; i < nn; i++) now3[i] = 1ll * num2[i] * num2[i] % P;
NTT(now3, nn, -1);
for (int i = 0; i < nn; i++) now4[i] = 1ll * num2[i] * num1[i] % P * num1[i] % P;
NTT(now4, nn, -1);
for (int i = 0; i < nn; i++) ans[i] = (1ll * (now1[i] + 8ll * now2[i] + 3ll * now3[i] - 6ll * now4[i] - 6ll *num4[i]) * inv24 % P + P) % P;
print();
return 0;
}
return 0;
}
标签:一个 bubuko 分时 struct log flag erro 额外 error
原文地址:https://www.cnblogs.com/yzhang-rp-inf/p/10343189.html