Submission #813454

# Submission time Handle Problem Language Result Execution time Memory
813454 2023-08-07T18:10:09 Z JakobZorz Nuclearia (CEOI15_nuclearia) C++14
55 / 100
1000 ms 43000 KB
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <stack>
#include <limits.h>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <cstring>
#include <sstream>
 
#pragma GCC target("popcnt")
 
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD=1e9+7;
typedef pair<ll,ll>point;
//#define x first
//#define y second

int w,h;

class Matrix{
    vector<ll>map_arr;
public:
    void init_map(){
        map_arr.resize(w*h);
    }

    ll get2(int x,int y){
        if(x<0||y<0)
            return 0;
        return map_arr[y*w+x];
    }

    ll&get(int x,int y){
        return map_arr[y*w+x];
    }

    void add_bounded(int x,int y,ll val){
        if(x<0)
            x=0;
        if(y<0)
            y=0;
        if(x>=w)
            return;
        if(y>=h)
            return;
        get(x,y)+=val;
    }
};
 
Matrix mat;
vector<ll>hor_vec;

void add_hor_line(int x1,int x2,ll val){
    if(x1>=x2)
        return;
    hor_vec[x1]+=val;
    if(x2<w)
        hor_vec[x2]-=val;
}

int main(){
    ios::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(NULL);
    
    cin>>w>>h;
    mat.init_map();
    hor_vec.resize(w);
    int n;
    cin>>n;
    while(n--){
        int x1,y1;
        ll center,step;
        cin>>x1>>y1>>center>>step;
        x1--;y1--;
        
        ll last_step=(center-1)%step+1;
        int num_steps=(int)(center+step-1)/step;
        
        if(x1>y1){
            // hits ceiling
            for(int i=0;i<num_steps-1&&i<y1;i++)
                mat.get(x1-i,y1-i)+=step;
            
            //add_hor_line(y1,min(num_steps-1,x1),step);
            for(int i=x1-y1;i>x1-min(num_steps-1,x1);i--)
                mat.get(i,0)+=step;
            
            if(x1<num_steps-1)
                mat.get(0,0)+=step*(num_steps-1-x1);
            
        }else{
            // hits left wall
            for(int i=0;i<num_steps-1&&i<x1;i++)
                mat.get(x1-i,y1-i)+=step;
            
            for(int i=x1;i<num_steps-1&&i<y1;i++)
                mat.get(0,y1-i)+=step;
            
            if(y1<num_steps-1)
                mat.get(0,0)+=step*(num_steps-1-y1);
        }
        
        if(x1+y1<w){
            // hits ceiling
            for(int i=0;i<num_steps-1&&i<y1;i++)
                mat.get(x1+i+1,y1-i)-=step;
            
            for(int i=y1;i<num_steps-1&&x1+i+1<w;i++)
                mat.get(x1+i+1,0)-=step;
            
        }else{
            for(int i=0;i<num_steps-1&&x1+i+1<w;i++)
                mat.get(x1+i+1,y1-i)-=step;
        }
        
        if(x1+y1<h){
            // hits left wall
            for(int i=0;i<num_steps-1&&i<x1;i++)
                mat.get(x1-i,y1+i+1)-=step;
            
            for(int i=x1;i<num_steps-1&&y1+i+1<h;i++)
                mat.get(0,y1+i+1)-=step;
            
        }else{
            for(int i=0;i<num_steps-1&&y1+i+1<h;i++)
                mat.get(x1-i,y1+i+1)-=step;
        }
        
        if(w-x1<h-y1){
            for(int i=0;i<num_steps-1&&x1+i+1<w;i++)
                mat.get(x1+i+1,y1+i+1)+=step;
        }else{
            for(int i=0;i<num_steps-1&&y1+i+1<h;i++)
                mat.get(x1+i+1,y1+i+1)+=step;
        }
        
        mat.add_bounded(x1-num_steps+1, y1-num_steps+1, last_step);
        mat.add_bounded(x1-num_steps+1, y1+num_steps,   -last_step);
        mat.add_bounded(x1+num_steps,   y1-num_steps+1, -last_step);
        mat.add_bounded(x1+num_steps,   y1+num_steps,   last_step);
        
        /*for(int x=0;x<w;x++)
            for(int y=0;y<h;y++){
                int dist=max(abs(x1-x),abs(y1-y));
                ll val=max(0LL,center-dist*step);
                get(x,y)+=val;
            }*/
    }
    
    for(int i=0;i<w;i++){
        if(i)
            hor_vec[i]+=hor_vec[i-1];
        mat.get(i,0)+=hor_vec[i];
    }
    
    for(int x=0;x<w;x++)
        for(int y=0;y<h;y++)
            mat.get(x,y)+=mat.get2(x-1,y)+mat.get2(x,y-1)-mat.get2(x-1,y-1);
    
    /*for(int y=0;y<h;y++){
        for(int x=0;x<w;x++){
            cout<<mat.get(x,y)<<" ";
        }
        cout<<"\n";
    }*/
    
    for(int x=0;x<w;x++)
        for(int y=0;y<h;y++)
            mat.get(x,y)+=mat.get2(x-1,y)+mat.get2(x,y-1)-mat.get2(x-1,y-1);
    
    int q;
    cin>>q;
    while(q--){
        int x1,y1,x2,y2;
        cin>>x1>>y1>>x2>>y2;
        x1--;y1--;
        
        ll sum=mat.get2(x2-1,y2-1)+mat.get2(x1-1,y1-1)-mat.get2(x1-1,y2-1)-mat.get2(x2-1,y1-1);
        
        ll area=(x2-x1)*(y2-y1);
        ll res=sum/area;
        if((sum%area)*2>=area)
            res++;
        cout<<res<<"\n";
    }

    return 0;
}

/*

4 3
2
1 1 7 3
3 2 4 2
4
1 2 2 3
1 1 4 3
4 2 4 2
1 3 4 3

*/
# Verdict Execution time Memory Grader output
1 Correct 129 ms 39380 KB Output is correct
2 Correct 47 ms 3540 KB Output is correct
3 Correct 43 ms 3200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 39364 KB Output is correct
2 Correct 46 ms 3524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 19924 KB Output is correct
2 Correct 46 ms 3532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 19796 KB Output is correct
2 Correct 46 ms 3564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 43000 KB Output is correct
2 Correct 50 ms 4040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 128 ms 19460 KB Output is correct
2 Correct 59 ms 3848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 23252 KB Output is correct
2 Correct 48 ms 4076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 15444 KB Output is correct
2 Correct 47 ms 3660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 39456 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1077 ms 39452 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 515 ms 24120 KB Output is correct
2 Correct 914 ms 24592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 828 ms 24464 KB Output is correct
2 Correct 503 ms 23840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1072 ms 20276 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 21832 KB Time limit exceeded
2 Halted 0 ms 0 KB -