답안 #813404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
813404 2023-08-07T17:14:03 Z JakobZorz Nuclearia (CEOI15_nuclearia) C++14
40 / 100
1000 ms 25640 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;

int main(){
    ios::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(NULL);
    
    cin>>w>>h;
    mat.init_map();
    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;
        
        for(int i=0;i<num_steps-1;i++){
            mat.add_bounded(x1-i,y1-i,step);
            mat.add_bounded(x1-i,y1+i+1,-step);
            mat.add_bounded(x1+i+1,y1-i,-step);
            mat.add_bounded(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 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
 
 */
# 결과 실행 시간 메모리 Grader output
1 Correct 288 ms 19796 KB Output is correct
2 Correct 48 ms 4520 KB Output is correct
3 Correct 44 ms 3788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 235 ms 19796 KB Output is correct
2 Correct 48 ms 4612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 19880 KB Output is correct
2 Correct 48 ms 4340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 19796 KB Output is correct
2 Correct 51 ms 4540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 25184 KB Output is correct
2 Correct 52 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 280 ms 13700 KB Output is correct
2 Correct 49 ms 4312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 128 ms 25304 KB Output is correct
2 Correct 51 ms 4576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 179 ms 13724 KB Output is correct
2 Correct 47 ms 4192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1081 ms 19796 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1080 ms 19796 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 654 ms 24912 KB Output is correct
2 Execution timed out 1012 ms 25640 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 915 ms 25172 KB Output is correct
2 Correct 465 ms 23956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1065 ms 20120 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1066 ms 20508 KB Time limit exceeded
2 Halted 0 ms 0 KB -