답안 #1012104

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1012104 2024-07-01T16:09:32 Z Do_you_copy Krave (COI14_krave) C++17
100 / 100
386 ms 80316 KB
#include <bits/stdc++.h>
//#define int long long
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());

ll min(const ll &a, const ll &b){
    return (a < b) ? a : b;
}
    
ll max(const ll &a, const ll &b){
    return (a > b) ? a : b;
}

//const ll Mod = 1000000007;
//const ll Mod2 = 999999999989;
const int inf = 1e9;
//only use when required
const int maxN = 1e5 + 1;
int n, a, b;

pair <int, int> getBound(int x, set <int> &S){
    int resl = 0, resr = inf;
    auto it = S.lower_bound(x);
    if (it != S.end()) resr = *it;
    if (it != S.begin()){
        --it;
        resl = *it;
    }
    return {resl, resr};
}

struct SegmentTree{
    vector <set <int>> st;
    SegmentTree(){
        st.resize(4 * maxN);
    }
    SegmentTree(int _n){
        st.resize(4 * _n);
        st[1].insert(0);
    }
    void update(int id, int i, int j, int x, int l, int r){
        if (i > r || j < l) return;
        // cerr << i << " " << j << " " << x << " " << l << " " << r << "?\n";
        if (i <= l && r <= j){
            st[id].insert(x);
            return;
        }
        int mid = (l + r) >> 1;
        update(id << 1, i, j, x, l, mid);
        update(id << 1 | 1, i, j, x, mid + 1, r);
    }
    pair <int, int> get(int id, int i, int j, int l, int r){
        if (i > r || i < l) return {0, inf};
        if (l == r){
            return getBound(j, st[id]);
        }
        int mid = (l + r) >> 1;
        pair <int, int> L = get(id << 1, i, j, l, mid);
        pair <int, int> R = get(id << 1 | 1, i, j, mid + 1, r);
        pair <int, int> M = getBound(j, st[id]);
        return {max({L.fi, R.fi, M.fi}), min({L.se, R.se, M.se})}; 
    }
};

void Init(){
    cin >> a >> b >> n;
    SegmentTree sta(a);
    SegmentTree stb(b);
    sta.st[1].insert(b);
    stb.st[1].insert(a);
    for (int i = 1; i <= n; ++i){
        int x, y, d;
        cin >> x >> y >> d;
        auto [lb, rb] = sta.get(1, x, y, 1, a);
        auto [la, ra] = stb.get(1, y, x, 1, b);
        // cerr << la << " " << ra << " " << lb << " " << rb << "\n";
        if (d == 1){
            ll res1 = 1LL * (ra - la) * (y - lb);
            ll res2 = 1LL * (ra - la) * (rb - y);
            cout << min(res1, res2) << " " << max(res1, res2) << "\n";
            sta.update(1, la + 1, ra, y, 1, a);
        }
        else{
            ll res1 = 1LL * (rb - lb) * (x - la);
            ll res2 = 1LL * (rb - lb) * (ra - x);
            cout << min(res1, res2) << " " << max(res1, res2) << "\n";
            stb.update(1, lb + 1, rb, x, 1, b);
        }
    }
}
    
#define taskname "test"
signed main(){
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    faster;
    ll tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
    if (fopen("timeout.txt", "r")){
        ofstream timeout("timeout.txt");
        timeout << 1000 * double(clock()) / CLOCKS_PER_SEC;
        #ifndef debug
        cerr << "\nTime elapsed: " << 1000 * double(clock()) / CLOCKS_PER_SEC << "ms\n";
        #endif
    }
}

Compilation message

krave.cpp: In function 'int main()':
krave.cpp:106:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
krave.cpp:107:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 38236 KB Output is correct
2 Correct 26 ms 38748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 43284 KB Output is correct
2 Correct 69 ms 32168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 43344 KB Output is correct
2 Correct 80 ms 36564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 43156 KB Output is correct
2 Correct 98 ms 41092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 172 ms 51796 KB Output is correct
2 Correct 211 ms 55636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 385 ms 66640 KB Output is correct
2 Correct 240 ms 64084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 386 ms 65872 KB Output is correct
2 Correct 209 ms 76116 KB Output is correct
3 Correct 82 ms 28560 KB Output is correct
4 Correct 248 ms 68248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 376 ms 66900 KB Output is correct
2 Correct 251 ms 80316 KB Output is correct
3 Correct 88 ms 36432 KB Output is correct
4 Correct 243 ms 72532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 355 ms 67272 KB Output is correct
2 Correct 183 ms 68364 KB Output is correct
3 Correct 95 ms 45648 KB Output is correct
4 Correct 295 ms 76372 KB Output is correct