답안 #681118

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
681118 2023-01-12T11:19:13 Z Cross_Ratio Nuclearia (CEOI15_nuclearia) C++14
15 / 100
1000 ms 79908 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];
long long int 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;
        }
        ll sum1 = 0, sum2 = 0;
        for(i=0;i<W;i++) {
            sum1 += F[i], sum2 += G[i];
            D[i] = i * sum1 + sum2;
            //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:81:76: warning: '*' in boolean context, suggest '&&' instead [-Wint-in-bool-context]
   81 |             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:90:77: warning: '*' in boolean context, suggest '&&' instead [-Wint-in-bool-context]
   90 |         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);
      |                                                                            ~^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 39892 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 39972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 272 ms 39828 KB Output is correct
2 Correct 52 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 214 ms 39548 KB Output is correct
2 Correct 53 ms 2628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 104 ms 40668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 102 ms 18464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 328 ms 41784 KB Output is correct
2 Correct 56 ms 2900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 591 ms 57416 KB Output is correct
2 Correct 55 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 208 ms 79908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 192 ms 79904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 39836 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1079 ms 39636 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1081 ms 40408 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1061 ms 39832 KB Time limit exceeded
2 Halted 0 ms 0 KB -