Submission #592660

# Submission time Handle Problem Language Result Execution time Memory
592660 2022-07-09T12:17:54 Z andrei_boaca Nuclearia (CEOI15_nuclearia) C++14
30 / 100
1000 ms 145748 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
typedef long long ll;
typedef long double ld;
vector<vector<ll>> v;
int n,m,k,q;
int nradds=0;
void add(int x1,int y1,int x2,int y2,ll val)
{
    x1=max(x1,1);
    y1=max(y1,1);
    x2=min(x2,n);
    y2=min(y2,m);
    v[x1][y1]+=val;
    v[x2+1][y1]-=val;
    v[x1][y2+1]-=val;
    v[x2+1][y2+1]+=val;
}
ll getsum(int x1,int y1,int x2,int y2)
{
    return v[x2][y2]-v[x1-1][y2]-v[x2][y1-1]+v[x1-1][y1-1];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m>>k;
    v.resize(n+2);
    for(int i=0;i<=n+1;i++)
        v[i].resize(m+2);
    bool subtask12=0;
    if(k*max(n,m)>1e8)
        subtask12=1;
    for(int z=1;z<=k;z++)
    {
        int x,y,a,b;
        cin>>x>>y>>a>>b;
        int nr=a;
        int x1=x,y1=y,x2=x,y2=y;
        int cnt=0;
        while(nr>0&&cnt<=max(n,m))
        {
            add(x1,y1,x2,y2,b);
            nr-=b;
            cnt++;
            x1--;
            x2++;
            y1--;
            y2++;
            if(x1<=0&&y1<=0&&x2>n&&y2>m)
                break;
            if(x1<=0&&subtask12)
                break;
            if(y1<=0&&subtask12)
                break;
            if(x2>n&&subtask12)
                break;
            if(y2>m&&subtask12)
                break;
        }
        //cout<<v[1][1]<<' ';
        x1++;
        x2--;
        y1++;
        y2--;
        add(x1,y1,x2,y2,a);
        add(x1,y1,x2,y2,-cnt*b);
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            v[i][j]+=v[i-1][j]+v[i][j-1]-v[i-1][j-1];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            v[i][j]=v[i][j]+v[i-1][j]+v[i][j-1]-v[i-1][j-1];
            //cout<<s[i][j]<<' ';
        }
    //assert(nradds<=k*max(n,m));
    cin>>q;
    while(q--)
    {
        int x1,y1,x2,y2;
        cin>>x1>>y1>>x2>>y2;
        ll suma=getsum(x1,y1,x2,y2);
        ll cells=(y2-y1+1)*(x2-x1+1);
        ll rez=round(ld(suma)/ld(cells));
        cout<<rez<<'\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 769 ms 137292 KB Output is correct
2 Correct 62 ms 2700 KB Output is correct
3 Correct 56 ms 2248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 731 ms 137180 KB Output is correct
2 Correct 69 ms 2660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 20096 KB Output is correct
2 Correct 61 ms 2700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 21844 KB Output is correct
2 Correct 79 ms 2712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 451 ms 139468 KB Output is correct
2 Correct 79 ms 2892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 723 ms 57420 KB Output is correct
2 Correct 86 ms 2716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 134 ms 22292 KB Output is correct
2 Correct 67 ms 2920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 576 ms 37840 KB Output is correct
2 Correct 77 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 471 ms 145748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 425 ms 145720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 723 ms 22116 KB Output is correct
2 Execution timed out 1082 ms 19924 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1038 ms 22200 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1094 ms 20692 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1020 ms 28592 KB Time limit exceeded
2 Halted 0 ms 0 KB -