Submission #56544548


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plll;
typedef pair<double,double> pdd;
typedef complex<double> cpx;
#define fastio cin.tie(0)->sync_with_stdio(0); cout.tie(0);
#define all(x) x.begin(),x.end()
#define compress(x) x.erase(unique(all(x)),x.end())
#define ff first
#define ss second
#define INF 1e17
#define SIZE 100010

ll n,q,a[110][110][110];

int main(){
    fastio;
    cin >> n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                cin >> a[i][j][k];
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                a[i][j][k] += a[i-1][j][k];
            }
        }
    }
    for(int j=1;j<=n;j++){
        for(int i=1;i<=n;i++){
            for(int k=1;k<=n;k++){
                a[i][j][k] += a[i][j-1][k];
            }
        }
    }
    for(int k=1;k<=n;k++){
        for(int j=1;j<=n;j++){
            for(int i=1;i<=n;i++){
                a[i][j][k] += a[i][j][k-1];
            }
        }
    }
    cin >> q;
    while(q--){
        ll l1,r1,l2,r2,l3,r3;
        cin >> l1 >> r1 >> l2 >> r2 >> l3 >> r3;
        l1--; l2--; l3--;
        ll ans = a[r1][r2][r3];
        ans -= a[l1][r2][r3]+a[r1][l2][r3]+a[r1][r2][l3];
        ans += a[l1][l2][r3]+a[l1][r2][l3]+a[r1][l2][l3];
        ans -= a[l1][l2][l3];
        cout << ans << "\n";
    }
}

Submission Info

Submission Time
Task D - Cuboid Sum Query
User Equinox_
Language C++ 20 (gcc 12.2)
Score 400
Code Size 1553 Byte
Status AC
Exec Time 92 ms
Memory 8228 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 22
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 02_maximum_00.txt, 02_maximum_01.txt, 02_maximum_02.txt, 02_maximum_03.txt, 02_maximum_04.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3408 KiB
00_sample_01.txt AC 1 ms 3500 KiB
01_random_00.txt AC 87 ms 7740 KiB
01_random_01.txt AC 68 ms 7996 KiB
01_random_02.txt AC 68 ms 6688 KiB
01_random_03.txt AC 57 ms 5540 KiB
01_random_04.txt AC 83 ms 7896 KiB
01_random_05.txt AC 57 ms 8096 KiB
01_random_06.txt AC 66 ms 6488 KiB
01_random_07.txt AC 49 ms 4608 KiB
01_random_08.txt AC 67 ms 7096 KiB
01_random_09.txt AC 68 ms 7336 KiB
01_random_10.txt AC 86 ms 7684 KiB
01_random_11.txt AC 75 ms 6912 KiB
01_random_12.txt AC 47 ms 4976 KiB
01_random_13.txt AC 77 ms 7828 KiB
01_random_14.txt AC 85 ms 8136 KiB
02_maximum_00.txt AC 92 ms 8148 KiB
02_maximum_01.txt AC 87 ms 8112 KiB
02_maximum_02.txt AC 85 ms 8124 KiB
02_maximum_03.txt AC 85 ms 8116 KiB
02_maximum_04.txt AC 85 ms 8228 KiB