QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#226723#7581. Radar Scanner8BQube#AC ✓476ms19204kbC++201.8kb2023-10-26 14:38:572023-10-26 14:38:57

Judging History

你现在查看的是最新测评结果

  • [2023-10-26 14:38:57]
  • 评测
  • 测评结果:AC
  • 用时:476ms
  • 内存:19204kb
  • [2023-10-26 14:38:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define pb push_back
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()

const int C = 1005;
typedef vector<vector<int>> M;

void add(M &v, int x1, int y1, int x2, int y2) {
    if (x1 > x2 || y1 > y2) return;
    v[x1][y1]++;
    v[x1][y2 + 1]--;
    v[x2 + 1][y1]--;
    v[x2 + 1][y2 + 1]++;
}

void intg(M &v) {
    for (int i = 1; i < C; i++)
        for (int j = 1; j < C; j++)
            v[i][j] += v[i - 1][j] + v[i][j - 1] - v[i - 1][j - 1];
}

ll c(ll a, ll b) {
    assert(b <= 3); 
    if (b > a) return 0;
    ll res = 1;
    for (int i = 0; i < b; i++)
        res *= (a - i);
    for (int i = 1; i <= b; i++)
        res /= i;
    return res;
}

void solve() {
    int n;
    cin >> n;
    M O(C, vector(C, 0));
    M U(C, vector(C, 0));
    M L(C, vector(C, 0));
    M LU(C, vector(C, 0));
    for (int i = 1; i <= n; i++) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        add(LU, x1, y1, x1, y1);
        add(L, x1 + 1, y1, x2, y1);
        add(U, x1, y1 + 1, x1, y2);
        add(O, x1 + 1, y1 + 1, x2, y2);
    }
    intg(O); intg(U); intg(L); intg(LU);
    ll ans = 0;
    for (int o = 0; o <= 3; o++)
        for (int u = 0; o + u <= 3; u++)
            for (int l = 0; o + u + l <= 3; l++) {
                int lu = 3 - l - u - o; 
                if (lu || (u && l))
                    for (int i = 1; i < C; i++)
                        for (int j = 1; j < C; j++)
                            ans += c(O[i][j], o) * c(U[i][j], u) * c(L[i][j], l) * c(LU[i][j], lu);
            }
    cout << ans << endl;
}


int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int T;
    cin >> T;
    while (T--)
        solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 67ms
memory: 19040kb

input:

2
3
3 1 3 1
1 1 2 3
2 1 3 2
5
1 1 4 5
2 1 3 2
2 2 3 3
4 5 4 5
1 2 2 4

output:

0
4

result:

ok 2 number(s): "0 4"

Test #2:

score: 0
Accepted
time: 476ms
memory: 19204kb

input:

10
5
2 1 3 3
1 5 1 5
1 2 2 3
4 1 5 3
1 2 4 4
10
3 3 7 5
3 4 3 4
5 4 6 6
8 1 10 6
6 1 9 8
2 6 8 10
3 2 8 7
5 1 5 8
2 2 7 7
1 1 2 3
100
1 37 28 37
1 5 6 40
9 29 47 30
12 9 12 9
40 14 45 14
13 28 16 34
44 8 46 47
23 9 40 42
13 1 35 17
9 31 46 31
1 10 34 48
5 35 46 50
16 21 28 49
3 6 3 24
5 3 39 28
30 8...

output:

1
31
16256
29932636832595
20948001862043
20395156087285
20094030388871
20143137954387
19922797032244
20114049116806

result:

ok 10 numbers