Submission #854968

# Submission time Handle Problem Language Result Execution time Memory
854968 2023-09-29T14:06:57 Z vjudge1 Nuclearia (CEOI15_nuclearia) C++17
65 / 100
681 ms 550804 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 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-x,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+3,vector<ll>(h+3,0));
    p2.resize(w+3,vector<ll>(h+3,0));
    p3.resize(w+3,vector<ll>(h+3,0));
    pre.resize(w+3,0);
    a2.resize(h+3,0);
    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];
    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();
}
# Verdict Execution time Memory Grader output
1 Correct 452 ms 548180 KB Output is correct
2 Correct 45 ms 2640 KB Output is correct
3 Correct 42 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 448 ms 548180 KB Output is correct
2 Correct 45 ms 2792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 59992 KB Output is correct
2 Incorrect 45 ms 4432 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 57 ms 69760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 565 ms 550448 KB Output is correct
2 Correct 49 ms 3156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 298 ms 222036 KB Output is correct
2 Correct 49 ms 2632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 139 ms 65360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 201 ms 112640 KB Output is correct
2 Incorrect 55 ms 4432 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 676 ms 550804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 681 ms 550760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 225 ms 62032 KB Output is correct
2 Correct 222 ms 61520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 228 ms 61800 KB Output is correct
2 Correct 217 ms 61480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 194 ms 70556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 203 ms 69436 KB Output isn't correct
2 Halted 0 ms 0 KB -