답안 #667854

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
667854 2022-12-02T07:19:05 Z BlackJack Krave (COI14_krave) C++14
10 / 100
859 ms 73020 KB
#include<bits/stdc++.h>
using namespace std;

void DBG() { cerr << "]\n"; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << h; if(sizeof...(t)) cerr << ", ";
    DBG(t...);
}
#ifdef LOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif // LOCAL

#define FOR(i,a,b) for(int i = (a) ; i<(b) ; i++)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for(int i = (b)-1 ; i>=(a) ; i--)
#define R0F(i,a) ROF(i,0,a)
#define each(e,a) for(auto &e : (a))
#define sz(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb push_back
#define tcT template<class T
#define nl "\n"
#define fi first
#define se second

using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
using str = string;
using db = long double;
tcT> using V = vector<T>;
tcT> using pqg = priority_queue<T,vector<T>,greater<T>>;

void setIO(string NAME = "") {
    cin.tie(0)->sync_with_stdio(0);
    if(sz(NAME)) {
        freopen((NAME + ".inp").c_str(),"r",stdin);
        freopen((NAME + ".out").c_str(),"w",stdout);
    }
}

tcT> bool ckmin(T&a, const T&b) {
    return b < a ? a=b,1 : 0; }
tcT> bool ckmax(T&a, const T&b) {
    return b > a ? a=b,1 : 0; }

const int MOD = 1e9 + 7;
const ll INF = 1e18;

const int MX = 1e5+5;

struct SegTree {
    set<int> seg[MX*4 + 7];
    int N;
    void init(int _SZ) {
        N = _SZ;
    }
    void addPoint(int l, int r, int pos, int ind, int L, int R) {
        if(l > R || r < L) return;
        if(l <= L && R <= r) {
            seg[ind].insert(pos);
            return;
        }
        int mid = (L + R) >> 1;
        addPoint(l, r, pos, ind<<1, L, mid);
        addPoint(l, r, pos, ind<<1|1, mid+1, R);
    }
    void addPoint(int l, int r, int pos) {
        addPoint(l, r, pos, 1, 0, N);
    }

    int query(int pos, int val, int ind, int L, int R) {
        if(R < pos || pos < L) return -1;
        auto it = seg[ind].upper_bound(val);
        int res = -1;
        if(it != seg[ind].begin()) {
            it--;
            res = *it;
        }

        if(L == R) return res;
        int mid = (L + R) >> 1;

        if(pos <= mid) ckmax(res, query(pos, val, ind<<1, L, mid));
        else ckmax(res, query(pos, val, ind<<1|1, mid+1, R));
        return res;
    }

    int query(int pos, int val) {
        return query(pos, val, 1, 1, N);
    }
};

struct Rect {
    int xl, yl, xr, yr;
    ll getArea() { return 1LL*(xr - xl)*(yr - yl); }
    Rect(int _xl = 0, int _yl = 0, int _xr = 0, int _yr = 0) {
        xl = _xl;
        yl = _yl;
        xr = _xr;
        yr = _yr;
    }
    bool operator<(const Rect&rhs) const {
        if(xl != rhs.xl) return xl < rhs.xl;
        return yl < rhs.yl;
    }
};

int A, B;

int N;

SegTree stX, stY;

set<Rect> s;

void solve() {
    cin >> A >> B;
    stY.init(A);
    stX.init(B);
    stY.addPoint(0, A, 0);
    stX.addPoint(0, B, 0);
    s.insert(Rect(0, 0, A, B));
    cin >> N;
    while(N-- > 0) {
        int x, y, dir;
        cin >> x >> y >> dir;
        int rect_y = stY.query(x, y), rect_x = stX.query(y, x);


        assert(rect_y >= 0 && rect_x >= 0);

        auto it = s.lower_bound(Rect(rect_x, rect_y, -1, -1));

        int xl = it->xl, yl = it->yl, xr = it->xr, yr = it->yr;

        s.erase(it);

        Rect newA, newB;

        if(dir == 1) {
            newA = Rect(xl, yl, xr, y);
            newB = Rect(xl, y, xr, yr);
            stY.addPoint(xl, xr, y);
        }
        else {
            newA = Rect(xl, yl, x, yr);
            newB = Rect(x, yl, xr, yr);
            stX.addPoint(yl, yr, x);
        }

        cout << min(newA.getArea(), newB.getArea()) << " " << max(newA.getArea(), newB.getArea()) << nl;

        s.insert(newA);
        s.insert(newB);
    }
}

int main() {
    setIO();

    int t=1;
    //cin>>t;
    while(t-->0) {
        solve();
    }

    return 0;
}

Compilation message

krave.cpp: In function 'void setIO(std::string)':
krave.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen((NAME + ".inp").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
krave.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen((NAME + ".out").c_str(),"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 37972 KB Output is correct
2 Correct 18 ms 37924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 38364 KB Output is correct
2 Correct 21 ms 38740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 120 ms 45812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 127 ms 45800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 143 ms 45796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 299 ms 53708 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 859 ms 73020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 767 ms 71760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 684 ms 72324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 695 ms 72884 KB Output isn't correct
2 Halted 0 ms 0 KB -