Submission #39502

# Submission time Handle Problem Language Result Execution time Memory
39502 2018-01-16T03:33:10 Z funcsr Nuclearia (CEOI15_nuclearia) C++14
55 / 100
936 ms 177936 KB
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i=0; i<(n); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
inline int abs(int x) {
  if (x < 0) return -x;
  return x;
}

int W, H, N, Q;
long long AL[2500000], AR[2500000], DL[2500000], DR[2500000];
long long T[2500000];
inline int p(int x, int y) { return y*W+x; }

vector<long long> B[2500000];

int main() {
  scanf("%d %d %d", &W, &H, &N);
  if (H > 1) {
    assert(W*H*N <= 1e8);
    rep(x, W) B[x].resize(H, 0);
    rep(i, N) {
      int x, y, a, b;
      scanf("%d %d %d %d", &x, &y, &a, &b);
      x--, y--;
      rep(xx, W) rep(yy, H) {
        int dist = max(abs(xx-x), abs(y-yy));
        B[xx][yy] += max(0LL, a-1LL*b*dist);
      }
    }
    rep(y, H) rep(x, W-1) B[x+1][y] += B[x][y];
    rep(y, H-1) rep(x, W) B[x][y+1] += B[x][y];
    scanf("%d", &Q);
    rep(i, Q) {
      int x1, y1, x2, y2;
      scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
      x1--, y1--, x2--, y2--;
      long long s = B[x2][y2];
      if (x1 > 0) s -= B[x1-1][y2];
      if (y1 > 0) s -= B[x2][y1-1];
      if (x1 > 0 && y1 > 0) s += B[x1-1][y1-1];
      long long q = 1LL*(x2-x1+1)*(y2-y1+1);
      //cout<<s<<"/"<<q<<"\n";
      printf("%lld\n", ((2LL*s/q)+1)/2);
    }
  }
  else {
    //cout<<"W="<<W<<",H="<<H<<", N="<<N<<"\n";
    rep(i, N) {
      int x, y, a, b;
      scanf("%d %d %d %d", &x, &y, &a, &b);
      x--, y--;
      AL[x] += a, AR[x] += a;
      DL[x] -= b, DR[x] -= b;
      T[x] -= a;
      int k = ((a+b-1)/b);
      if (x-k >= 0) DL[x-k] += b, AL[x-k] += (b-a%b)%b;
      if (x+k < W) DR[x+k] += b, AR[x+k] += (b-a%b)%b;
    }
    long long cur = 0, d = 0;
    rep(x, W) {
      cur += AR[x] + d;
      T[x] += cur;
      d += DR[x];
    }
    cur = 0, d = 0;
    for (int x=W-1; x>=0; x--) {
      cur += AL[x] + d;
      T[x] += cur;
      d += DL[x];
    }
    //rep(x, W) cout <<T[x]<<",";cout<<"\n";

    rep(y, H) rep(x, W-1) T[p(x+1, y)] += T[p(x, y)];
    rep(y, H-1) rep(x, W) T[p(x, y+1)] += T[p(x, y)];
    scanf("%d", &Q);
    rep(i, Q) {
      int x1, y1, x2, y2;
      scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
      x1--, y1--, x2--, y2--;
      long long s = T[p(x2, y2)];
      if (x1 > 0) s -= T[p(x1-1, y2)];
      if (y1 > 0) s -= T[p(x2, y1-1)];
      if (x1 > 0 && y1 > 0) s += T[p(x1-1, y1-1)];
      long long q = 1LL*(x2-x1+1)*(y2-y1+1);
      //cout<<s<<"/"<<q<<"\n";
      printf("%lld\n", ((2LL*s/q)+1)/2);
    }
  }
  return 0;
}

Compilation message

nuclearia.cpp: In function 'int main()':
nuclearia.cpp:24:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &W, &H, &N);
                                ^
nuclearia.cpp:30:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d %d %d %d", &x, &y, &a, &b);
                                           ^
nuclearia.cpp:39:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &Q);
                    ^
nuclearia.cpp:42:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
                                               ^
nuclearia.cpp:57:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d %d %d %d", &x, &y, &a, &b);
                                           ^
nuclearia.cpp:82:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &Q);
                    ^
nuclearia.cpp:85:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
                                               ^
# Verdict Execution time Memory Grader output
1 Correct 29 ms 158268 KB Output is correct
2 Correct 126 ms 158268 KB Output is correct
3 Correct 133 ms 158268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 158268 KB Output is correct
2 Correct 133 ms 158268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 363 ms 177936 KB Output is correct
2 Correct 123 ms 158268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 306 ms 177868 KB Output is correct
2 Correct 119 ms 158268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 203 ms 158268 KB Output is correct
2 Correct 139 ms 158268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 179 ms 158268 KB Output is correct
2 Correct 146 ms 158268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 539 ms 177804 KB Output is correct
2 Correct 173 ms 158268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 936 ms 173844 KB Output is correct
2 Correct 106 ms 158268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 496 ms 158268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 459 ms 158268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 158272 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 158272 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 158272 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 158272 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -