QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#702440 | #7785. Three Rectangles | qiuuu# | RE | 0ms | 0kb | C++23 | 3.7kb | 2024-11-02 15:59:35 | 2024-11-02 15:59:35 |
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define OPFI(x) freopen(#x".in", "r", stdin);\
freopen(#x".out", "w", stdout)
#define REP(i, a, b) for(int i=(a); i<=(b); ++i)
#define REPd(i, a, b) for(int i=(a); i>=(b); --i)
inline ll rd(){
ll r=0, k=1; char c; while(!isdigit(c=getchar())) if(c=='-') k=-k;
while(isdigit(c)) r=r*10+c-'0', c=getchar(); return r*k;
}
constexpr int MOD=1e9+7;
ll t, H, W, h[10], w[10];
int main(){
OPFI(test1);
t=rd();
while(t--){
H=rd(), W=rd();
int tmp=0, flag=0, hhf=0, wwf=0;
REP(i, 1, 3){
h[i]=rd(), w[i]=rd();
if(h[i]==H||w[i]==W) ++tmp;
if(h[i]==H) ++hhf;
if(w[i]==W) ++wwf;
if(h[i]==H&&w[i]==W) flag=1;
}
if(flag){
ll ans=1;
REP(i, 1, 3) ans=ans*(H-h[i]+1)%MOD*(W-w[i]+1)%MOD;
printf("%lld\n", ans);
continue;
}
if(tmp==0){
puts("0");
}else if(tmp==1){
if(wwf){
swap(H, W);
swap(h[1], w[1]);
swap(h[2], w[2]);
swap(h[3], w[3]);
}
ll sumh=h[1]+h[2]+h[3]-H;
ll mnw=W, anw=0;
REP(i, 1, 3) if(h[i]!=H) mnw=min(mnw, w[i]); else anw=w[i];
if(mnw+anw>=W&&sumh>=H) puts("4");
else puts("0");
}else if(tmp==2){
if(wwf==2||hhf==2){
if(wwf){
swap(H, W);
swap(h[1], w[1]);
swap(h[2], w[2]);
swap(h[3], w[3]);
}
ll sumw=0, anh=0, anw=0;
REP(i, 1, 3) if(h[i]==H) sumw+=w[i]; else anh=h[i], anw=w[i];
if(sumw>=W){
printf("%lld\n", 2*(H-anh+1)%MOD*(W-anw+1)%MOD);
}else puts("0");
}else{
ll sumh=h[1]+h[2]+h[3]-H;
ll sumw=w[1]+w[2]+w[3]-W;
if(sumh>=H&&sumw>=W) puts("4");
else puts("0");
}
}else if(tmp==3){
if(wwf==3||hhf==3){
if(wwf){
swap(H, W);
swap(h[1], w[1]);
swap(h[2], w[2]);
swap(h[3], w[3]);
}
ll s=w[1]+w[2]+w[3];
if(s>=W){
ll ans=0;
REP(i, 1, 3){
if(s-w[i]>=W){
ans=(ans+2*(W-w[i]-1)+2)%MOD;
continue;
}
ll x=w[1], y=w[3];
if(i==1) x=w[2];
if(i==3) y=w[2];
ll top=max(1LL, W-y-w[i]), but=min(W-w[i]-1, x);
// cerr<<t<<": "<<top<<" "<<but<<endl;
ans=(ans+2*(but-top+1))%MOD;
if(w[i]+y>=W) ans=(ans+1)%MOD;
if(x+w[i]>=W) ans=(ans+1)%MOD;
}
printf("%lld\n", ans%MOD);
}else puts("0");
}else{
if(wwf==2){
swap(H, W);
swap(h[1], w[1]);
swap(h[2], w[2]);
swap(h[3], w[3]);
}
ll sumw=0, anh=0, anw=0;
REP(i, 1, 3) if(h[i]==H) sumw+=w[i]; else anh=h[i], anw=w[i];
if(sumw>=W){
printf("%lld\n", 2*(H-anh+1)%MOD*(W-anw+1)%MOD);
}else puts("0");
}
}
}
return 0;
}
詳細信息
Test #1:
score: 0
Dangerous Syscalls
input:
5 2 2 1 1 1 1 1 1 2 2 1 1 1 2 1 2 2 2 1 1 1 2 2 1 2 2 1 2 1 2 1 2 2 2 1 2 1 2 2 1