Submission #386913

#TimeUsernameProblemLanguageResultExecution timeMemory
386913FatihSolakNuclearia (CEOI15_nuclearia)C++17
0 / 100
1100 ms237932 KiB
#include <bits/stdc++.h>
using namespace std;
int main(){
    bool swp = 0;
    int w,h;
    scanf("%d %d",&w,&h);
    if(w < h){
        swp = 1;
        swap(w,h);
    }
    long long arr[h+5][h+w+5];
    long long pre[h+5][h+w+5];
    for(int i=0;i<h+5;i++){
        for(int j = 0;j<h+w+5;j++){
            arr[i][j] = pre[i][j] = 0;
        }
    }    
    int n;
    scanf("%d ",&n);
    for(int i=0;i<n;i++){
        int x,y,a,b;
        scanf("%d %d %d %d",&x,&y,&a,&b);
        if(swp)swap(x,y);
        x += h;
        for(int i=1;i<=h;i++){
            int dif = abs(y-i);
            if(dif * b > a)continue;

            arr[i][max(1,x-dif+1)] -= b;
            arr[i][max(1,x-(a/b)+1)] += b;
            arr[i][max(1,x-(a/b))] += a - b*(x - max(1,x-(a/b)));
            arr[i][max(1,x-(a/b)) + 1] -= a - b*(x - max(1,x-(a/b)));

            arr[i][min(w+h+1,x+dif+1)] -= b;
            arr[i][min(w+h+1,x+(a/b)+1)] += b;
            arr[i][min(w+h+1,x+(a/b)+1)] -= a%b;
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w+h;j++){
            arr[i][j] += arr[i][j-1];
        }
        for(int j=1;j<=w+h;j++){
            arr[i][j] += arr[i][j-1];
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=h+1;j<=w+h;j++){
            pre[i][j] = pre[i-1][j] + pre[i][j-1] - pre[i-1][j-1]+arr[i][j];
        }
    }
    int q;
    scanf("%d",&q);
    while(q--){
        int x1,y1,x2,y2;
        scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
        if(!swp)swap(x1,y1),swap(x2,y2);
        y1 += h;
        y2 += h;
        long double cnt = (x2-x1+1) * (y2 -y1+1);
        long long x = ((pre[x2][y2] - pre[x2][y1-1] - pre[x1 -1][y2] + pre[x1-1][y1-1])/cnt + 0.5);
        printf("%lld \n",x);
    }
}

Compilation message (stderr)

nuclearia.cpp: In function 'int main()':
nuclearia.cpp:6:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    6 |     scanf("%d %d",&w,&h);
      |     ~~~~~^~~~~~~~~~~~~~~
nuclearia.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |     scanf("%d ",&n);
      |     ~~~~~^~~~~~~~~~
nuclearia.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 |         scanf("%d %d %d %d",&x,&y,&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
nuclearia.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   53 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
nuclearia.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   56 |         scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...