Submission #716220

# Submission time Handle Problem Language Result Execution time Memory
716220 2023-03-29T09:32:07 Z Kutan Plahte (COCI17_plahte) C++14
0 / 160
684 ms 524288 KB
// Cao Quang Hung
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<long long , long long>
#define vi vector<int>
#define vpii vector<pii>
#define SZ(x) ((int)(x.size()))
#define fi first
#define se second
#define IN(x,y) ((y).find((x))!=(y).end())
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define FOR(i, n) for (int (i) = 0; (i) < (n); ++(i))
#define dem(x) __builtin_popcount(x)
#define Mask(x) (1LL << (x))
#define BIT(x, i) ((x) >> (i) & 1)
#define ln '\n'
#define io_faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
///mt19937 rnd(time(0));

const int INF = 1e9 , mod = 1e9 + 7;

template <class T1, class T2>
inline T1 mul(T1& x, const T2 &k){ return x = (1LL * x * k) % mod; }

template <class T1 , class T2>
inline T1 pw(T1 x, T2 k){T1 res = 1; for (; k ; k >>= 1){ if (k & 1) mul(res, x); mul(x, x); } return res;}

template <class T>
inline bool minimize(T &x, const T &y){ if (x > y){x = y; return 1;} return 0; }

template <class T>
inline bool maximize(T &x, const T &y){ if (x < y){x = y; return 1;} return 0; }

template <class T>
inline void add(T &x , const T &y){ if ((x += y) >= mod) x -= mod; }

template <class T>
inline T product (const T &x , const T &y) { return 1LL * x * y % mod; }

#define PROB "a"
void file(){
    if(fopen(PROB".inp", "r")){
        freopen(PROB".inp","r",stdin);
        freopen(PROB".out","w",stdout);
    }
}
void sinh_(){
//    srand(time(0));
//    freopen(PROB".inp" , "w" , stdout);
//    int n;
}

typedef long long ll;
typedef double db;

const int maxn = 2e6 + 20;
const int Bound = 2e6 + 6;
const int off = 1e6 + 2;
const int N = 1e5 + 5;

int n, q;
struct rect{
    int x[2], y[2];
    rect(){}
} hcn[N];

struct three{
    int x, l, r;
    three(int _x = 0, int _l = 0, int _r = 0){
        x = _x, l = _l, r = _r;
    }
    bool operator < (const three &other) const{
        return x < other.x;
    }
};

vector<three> row, col;
ll ansrow[maxn] = {}, anscol[maxn] = {};
int query[N];

void readip(){
    cin >> n;
    REP(i, 1, n){
        cin >> hcn[i].x[0] >> hcn[i].y[0];
        cin >> hcn[i].x[1] >> hcn[i].y[1];
    }    
    cin >> q;
    int x1=0, x2=0, y1=0, y2=0;
    REP(i, 1, q){
        cin >> query[i];    
        REP(j, y2 + 1, query[i]) row.push_back(three(j, -query[i], +query[i]));
        REPD(j, y1 - 1, -query[i]) row.push_back(three(j, -query[i], +query[i]));
        REPD(j, x1 - 1, -query[i]) col.push_back(three(j, y1, y2));
        REP(j, x2 + 1, query[i]) col.push_back(three(j, y1, y2));
        x1 = y1 = -query[i];
        x2 = y2 = query[i];
    }
}

struct event{
    int x, l, r, ins, type;
    event(int _x = 0, int _l = 0, int _r = 0, int _ins = 0, int _type = 0){
        x = _x, l = _l, r = _r, ins = _ins, type = _type;
    }
    bool operator < (const event &other) const{
        if (x == other.x) return type < other.type;
        return x < other.x;
    }
};

struct Fenwick{
    ll fen[2][maxn] = {};
    void build(){
        REP(i, 0, Bound) 
            fen[0][i] = fen[1][i] = 0;
    }
    void update_point(int i, int u, ll v){
        for (; u <= Bound; u += u & -u)
            fen[i][u] += v;
    }
    void update(int l, int r, ll v){
        update_point(0, l, 1LL* (Bound - l + 1) * v);
        update_point(0, r+1, -1LL * (Bound - r) * v);
        update_point(1, l, v);
        update_point(1, r+1, -v);
    }
    ll get(int i, int u){
        ll res = 0;
        for (; u > 0; u -= u &-u) res += fen[i][u];
        return res;
    }
    ll presum(int u){
        if (u == 0) return 0;
        return get(0, u) - get(1, u) * 1LL * (Bound - u);
    }
    ll getsum(int u, int v){
        return presum(v) - presum(u-1);
    }
} ST;

void solve(){   
    vector<event> E;
    REP(i, 1, n) {
        E.pb(event(hcn[i].y[0], hcn[i].x[0], hcn[i].x[1], +1, 1));
        E.pb(event(hcn[i].y[1]+1, hcn[i].x[0], hcn[i].x[1], -1, 1));
    }
    FOR(i, row.size())
        E.pb(event(row[i].x , row[i].l, row[i].r, 0, 2));
    
    sort(ALL(E)); 
    ST.build();
    for (event e : E){
        if (e.type == 2){
            ansrow[e.x + off] = ST.getsum(e.l + off, e.r + off);
        }
        else{
            ST.update(e.l + off, e.r + off, e.ins);
        }
    }

    E.clear();
    ST.build();
    REP(i, 1, n) {
        E.pb(event(hcn[i].x[0], hcn[i].y[0] , hcn[i].y[1], +1, 1));
        E.pb(event(hcn[i].x[1] + 1, hcn[i].y[0], hcn[i].y[1], -1, 1));
    }
    FOR(i, col.size()) 
        E.pb(event(col[i].x, col[i].l, col[i].r, 0, 2));
    sort(ALL(E));
    for (event e : E){
        if (e.type == 2){
            anscol[e.x + off] = ST.getsum(e.l + off, e.r + off);
        }
        else ST.update(e.l + off, e.r + off, e.ins);
    }
    ll res = 0;
    int x1 = 0, x2 = 0, y1 = 0, y2 = 0;
    REP(i, 1, q){
        while(x1 >= -query[i]) res += ansrow[x1+off] , --x1;
        while(x2 <= query[i]) res += ansrow[x2+off], ++x2;
        while(y1 >= -query[i]) res += anscol[y1+off], --y1;
        while(y2 <= query[i]) res += anscol[y2+off], ++y2;
        cout << res << ln;
    }
}

signed main(){
    sinh_();
    io_faster
    file();
    int t = 1;
//    cin >> t;
    while (t--){
        readip();
        solve();
    }
}

Compilation message

plahte.cpp: In function 'void readip()':
plahte.cpp:92:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   92 | #define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
      |                            ^
plahte.cpp:165:5: note: in expansion of macro 'REP'
  165 |     REP(i, 1, n){
      |     ^~~
plahte.cpp:92:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   92 | #define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
      |                            ^
plahte.cpp:171:5: note: in expansion of macro 'REP'
  171 |     REP(i, 1, q){
      |     ^~~
plahte.cpp:92:28: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   92 | #define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
      |                            ^
plahte.cpp:173:9: note: in expansion of macro 'REP'
  173 |         REP(j, y2 + 1, query[i]) row.push_back(three(j, -query[i], +query[i]));
      |         ^~~
plahte.cpp:93:29: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   93 | #define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
      |                             ^
plahte.cpp:174:9: note: in expansion of macro 'REPD'
  174 |         REPD(j, y1 - 1, -query[i]) row.push_back(three(j, -query[i], +query[i]));
      |         ^~~~
plahte.cpp:93:29: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   93 | #define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
      |                             ^
plahte.cpp:175:9: note: in expansion of macro 'REPD'
  175 |         REPD(j, x1 - 1, -query[i]) col.push_back(three(j, y1, y2));
      |         ^~~~
plahte.cpp:92:28: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   92 | #define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
      |                            ^
plahte.cpp:176:9: note: in expansion of macro 'REP'
  176 |         REP(j, x2 + 1, query[i]) col.push_back(three(j, y1, y2));
      |         ^~~
plahte.cpp: In member function 'void Fenwick::build()':
plahte.cpp:92:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   92 | #define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
      |                            ^
plahte.cpp:196:9: note: in expansion of macro 'REP'
  196 |         REP(i, 0, Bound)
      |         ^~~
plahte.cpp: In function 'void solve()':
plahte.cpp:92:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   92 | #define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
      |                            ^
plahte.cpp:225:5: note: in expansion of macro 'REP'
  225 |     REP(i, 1, n) {
      |     ^~~
plahte.cpp:94:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   94 | #define FOR(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
plahte.cpp:229:5: note: in expansion of macro 'FOR'
  229 |     FOR(i, row.size())
      |     ^~~
plahte.cpp:94:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<three>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 | #define FOR(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                                     ~~~~^~~~~
plahte.cpp:229:5: note: in expansion of macro 'FOR'
  229 |     FOR(i, row.size())
      |     ^~~
plahte.cpp:92:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   92 | #define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
      |                            ^
plahte.cpp:245:5: note: in expansion of macro 'REP'
  245 |     REP(i, 1, n) {
      |     ^~~
plahte.cpp:94:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   94 | #define FOR(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
plahte.cpp:249:5: note: in expansion of macro 'FOR'
  249 |     FOR(i, col.size())
      |     ^~~
plahte.cpp:94:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<three>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 | #define FOR(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                                     ~~~~^~~~~
plahte.cpp:249:5: note: in expansion of macro 'FOR'
  249 |     FOR(i, col.size())
      |     ^~~
plahte.cpp:92:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   92 | #define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
      |                            ^
plahte.cpp:260:5: note: in expansion of macro 'REP'
  260 |     REP(i, 1, q){
      |     ^~~
plahte.cpp: In function 'void file()':
plahte.cpp:125:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  125 |         freopen(PROB".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
plahte.cpp:126:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  126 |         freopen(PROB".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 663 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 678 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 684 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 645 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 681 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -