답안 #681117

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
681117 2023-01-12T11:15:19 Z Cross_Ratio Nuclearia (CEOI15_nuclearia) C++14
15 / 100
1000 ms 57452 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<N;i++) {
            sum1 += F[i], sum2 += G[i];
            D[i] = i * sum1 + sum2;
        }
        for(i=0;i<N;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[d] - (b?E[b-1]:0);
            ll x = d-b+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:79:76: warning: '*' in boolean context, suggest '&&' instead [-Wint-in-bool-context]
   79 |             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:88:77: warning: '*' in boolean context, suggest '&&' instead [-Wint-in-bool-context]
   88 |         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 1 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 852 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 305 ms 39832 KB Output is correct
2 Correct 64 ms 4256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 39508 KB Output is correct
2 Correct 61 ms 4556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 75 ms 2432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 72 ms 3940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 344 ms 41804 KB Output is correct
2 Correct 63 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 610 ms 57452 KB Output is correct
2 Correct 52 ms 2724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 235 ms 52240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 190 ms 52260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1090 ms 39836 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1088 ms 39636 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1090 ms 40404 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1090 ms 39836 KB Time limit exceeded
2 Halted 0 ms 0 KB -