답안 #854967

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854967 2023-09-29T13:48:59 Z vjudge1 Nuclearia (CEOI15_nuclearia) C++17
65 / 100
915 ms 910364 KB
#include<bits/stdc++.h>
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=2e5;
const ll inf=1e18;
const ll mod=1e9+7;
ll h,w;
vector<vector<ll>> p1,p2,p3;
vector<ll>a2,pre;
ll cd=0;
void add(ll x,ll y,ll a,ll b)
{
    ll r=(a-1)/b;
    // p1 p2 p3
    // p1 la prefix sum cho a
    // p2 la prefix sum cho b cheo 1
    // p3 la prefix sum cho b cheo 2
    p1[max(1ll,x-r)][max(1ll,y-r)]+=a-(r+1)*b;
    p1[min(x+r+1,w+1)][max(1ll,y-r)]-=a-(r+1)*b;
    p1[max(1ll,x-r)][min(h+1,y+r+1)]-=a-(r+1)*b;
    p1[min(w+1,x+r+1)][min(h+1,y+r+1)]+=a-(r+1)*b;

    ll k=min({x-1,y-1,r});
    p2[x-k][y-k]+=b;
    if(k!=r&&x<y)
    {
        a2[max(0ll,y-r)]+=b;
        a2[y-k]-=b;
    }
    k=min({w-x,h-y,r});
    p2[x+k+2][y+k+2]-=b;
    k=min({r,x-1,h-y});
    p3[x-k][y+k+1]-=b;
    if(k!=r&&x-1<h-y)
    {
        a2[y+k+2]-=b;
        a2[min(y+r+1,h+1)]+=b;
    }
    k=min({r,w-k,y-1});
    p3[x+k+2][y-k-1]+=b;

    if(r>y-1)
    {
        // cham y=0 khi nao
        ll bk=r-y;
        ll L=x-y;
        ll R=x+y+1;
        // time for update
        //cout << L-bk<<'\n';
        if(L>=1)
        {
            pre[L+1]-=b;
            pre[max(1ll,L-bk)]+=b;
            if(L-bk<1)
            {
                cd+=(1-L+bk)*b;

            }
        }
        else
        {
            cd+=(bk+1)*b;
        }
        if(R<=w)
        {
            pre[R]-=b;
            pre[min(w+1,R+bk+1)]+=b;
        }

    }
}
ll n;
using ld=long double;
ll get(ll x1,ll y1,ll x2,ll y2)
{
    return p1[x2][y2]-p1[x1-1][y2]-p1[x2][y1-1]+p1[x1-1][y1-1];
}

void solve()
{
    cin >> w >> h;
    p1.resize(w+10,vector<ll>(h+10));
    p2.resize(w+10,vector<ll>(h+10));
    p3.resize(w+10,vector<ll>(h+10));
    pre.resize(w+10);
    a2.resize(h+10);
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        ll x,y,a,b;
        cin >> x >> y >> a >> b;
        add(x,y,a,b);
    }
    for(int i=1;i<=w;i++) for(int j=1;j<=h;j++) p2[i][j]+=p2[i-1][j-1];
    for(int i=1;i<=w;i++) for(int j=h;j>=1;j--) p3[i][j]+=p3[i-1][j+1];
    for(int i=1;i<=w;i++) for(int j=1;j<=h;j++) p2[i][j]+=p3[i][j];
    for(int i=1;i<=h;i++)
    {
        a2[i]+=a2[i-1];
        p2[0][i]=a2[i];
    }
    for(int i=1;i<=w;i++) for(int j=1;j<=h;j++) p2[i][j]+=p2[i-1][j];
    // do something here
    for(int i=1;i<=w;i++)
    {
        pre[i]+=pre[i-1];
    }
    pre[0]=cd;
    for(int i=1;i<=w;i++) pre[i]+=pre[i-1];
    for(int i=1;i<=w;i++)
    {
        p2[i][0]=pre[i];
        //cout << pre[i]<<' ';
    }
    for(int i=1;i<=w;i++) for(int j=1;j<=h;j++) p2[i][j]+=p2[i][j-1];
    for(int i=1;i<=w;i++) for(int j=1;j<=h;j++) p1[i][j]+=p1[i-1][j];
    for(int i=1;i<=w;i++) for(int j=1;j<=h;j++) p1[i][j]+=p1[i][j-1];
    for(int i=1;i<=w;i++) for(int j=1;j<=h;j++) p1[i][j]+=p2[i][j];
    for(int i=1;i<=w;i++) for(int j=1;j<=h;j++) p1[i][j]+=p1[i-1][j]+p1[i][j-1]-p1[i-1][j-1];
    ll q;
    cin >> q;
    for(int i=1;i<=q;i++)
    {
        ll x1,y1,x2,y2;
        cin >> x1 >> y1 >> x2 >> y2;
        ll sum=get(x1,y1,x2,y2);
        ll sz=(x2-x1+1)*(y2-y1+1);
        cout << sum/sz+(sum%sz>=(sz+1)/2)<<'\n';
    }
}
int main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 692 ms 900648 KB Output is correct
2 Correct 46 ms 4772 KB Output is correct
3 Correct 43 ms 3920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 692 ms 900560 KB Output is correct
2 Correct 46 ms 4780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 72 ms 123380 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 68 ms 90588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 819 ms 906488 KB Output is correct
2 Correct 50 ms 5716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 393 ms 366408 KB Output is correct
2 Correct 46 ms 4688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 75 ms 122292 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 287 ms 209668 KB Output is correct
2 Runtime error 1 ms 600 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 912 ms 910364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 915 ms 910360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 70320 KB Output is correct
2 Correct 238 ms 69460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 69716 KB Output is correct
2 Correct 227 ms 70092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 77 ms 130740 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 75 ms 123400 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -