Submission #681120

# Submission time Handle Problem Language Result Execution time Memory
681120 2023-01-12T11:24:56 Z Cross_Ratio Nuclearia (CEOI15_nuclearia) C++14
15 / 100
1000 ms 99548 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
vector<vector<long long int>> A, B;
long long int D[2500005];
long long int E[2500005];
long long int F[2500005];
__int128 G[2500005];
array<long long int, 4> C[200005];
signed main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int W, H;
    cin >> W >> H;
    if(H==1) {
        int i, j;
        int N;
        cin >> N;
        for(i=0;i<N;i++) {
            ll a, b, c, d;
            cin >> a >> b >> c >> d;
            a--, b--;
            ll k = c/d;
            ll l = max(0LL, a-k);
            ll r = min((ll)W-1, a+k);
            F[l] += d;
            G[l] += c - d*a;
            F[a+1] -= d;
            G[a+1] -= c - d*a;
            F[a+1] += -d;
            G[a+1] += c+d*a;
            F[r+1] -= -d;
            G[r+1] -= c+d*a;
        }
        __int128 sum1 = 0, sum2 = 0;
        for(i=0;i<W;i++) {
            sum1 += F[i], sum2 += G[i];
            __int128 v = (__int128) i * sum1 + sum2;
            D[i] = v;
            //cout << D[i] << ' ';
        }
        //cout << '\n';
        for(i=0;i<W;i++) E[i] = (i ? E[i-1] : 0) + D[i];
        int Q;
        cin >> Q;
        while(Q--) {
            ll a, b, c, d;
            cin >> a >> b >> c >> d;
            a--, b-- ,c--, d--;
            ll val = E[c] - (a?E[c-1]:0);
            ll x = c-a+1;
            ll y = val / x;
            if(2*(val%x)>=x) y++;
            cout << y << '\n';
        }
        return 0;
    }
    A.resize(W);
    B.resize(W);
    int i, j;
    for(i=0;i<W;i++) {
        A[i].resize(H);
        B[i].resize(H);
    }
    int N;
    cin >> N;
    for(i=0;i<N;i++) {
        cin >> C[i][0] >> C[i][1] >> C[i][2] >> C[i][3];
        C[i][0]--, C[i][1]--;
        for(j=0;j<W;j++) {
            for(register int k = 0; k < H; k++) {
                A[j][k] += max(0LL, C[i][2] - max(abs(j-C[i][0]),abs(k-C[i][1])) * C[i][3]);
            }
        }
    }
    for(i=0;i<W;i++) {
        for(j=0;j<H;j++) {
            B[i][j] = (i?B[i-1][j]:0) + (j?B[i][j-1]:0) - ((long long int)i*j?B[i-1][j-1]:0) + A[i][j];
        }
    }
    int Q;
    cin >> Q;
    while(Q--) {
        long long int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--, b--, c--, d--;
        long long int val = B[c][d] - (a?B[a-1][d]:0) - (b?B[c][b-1]:0) + (a*b?B[a-1][b-1]:0);
        //cout << val << '\n

        long long int x = (c-a+1)* (d-b+1);
        long long int y = val / x;
        if(2*(val % x) >= x) y++;
        cout << y << '\n';
    }
}

Compilation message

nuclearia.cpp: In function 'int main()':
nuclearia.cpp:20:16: warning: unused variable 'j' [-Wunused-variable]
   20 |         int i, j;
      |                ^
nuclearia.cpp:82:76: warning: '*' in boolean context, suggest '&&' instead [-Wint-in-bool-context]
   82 |             B[i][j] = (i?B[i-1][j]:0) + (j?B[i][j-1]:0) - ((long long int)i*j?B[i-1][j-1]:0) + A[i][j];
      |                                                            ~~~~~~~~~~~~~~~~^~
nuclearia.cpp:91:77: warning: '*' in boolean context, suggest '&&' instead [-Wint-in-bool-context]
   91 |         long long int val = B[c][d] - (a?B[a-1][d]:0) - (b?B[c][b-1]:0) + (a*b?B[a-1][b-1]:0);
      |                                                                            ~^~
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 39884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 40020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 264 ms 39840 KB Output is correct
2 Correct 54 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 227 ms 39508 KB Output is correct
2 Correct 57 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 119 ms 40724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 97 ms 18492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 319 ms 41804 KB Output is correct
2 Correct 55 ms 2892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 604 ms 57428 KB Output is correct
2 Correct 52 ms 2656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 219 ms 99548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 216 ms 99424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 39840 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1101 ms 39636 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 40412 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 39852 KB Time limit exceeded
2 Halted 0 ms 0 KB -