Submission #308343

# Submission time Handle Problem Language Result Execution time Memory
308343 2020-10-01T00:47:04 Z caoash Krave (COI14_krave) C++14
5 / 100
5000 ms 45816 KB
#include <bits/stdc++.h> 
using namespace std;

using ll = long long;

using vi = vector<int>;
using vl = vector<ll>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair

const int MX = 100005;
const int MOD = (int) (1e9 + 7);
const ll INF = (ll) 1e18;

namespace output {
  void pr(int x) {
    cout << x;
  }
  void pr(long x) {
    cout << x;
  }
  void pr(ll x) {
    cout << x;
  }
  void pr(unsigned x) {
    cout << x;
  }
  void pr(unsigned long x) {
    cout << x;
  }
  void pr(unsigned long long x) {
    cout << x;
  }
  void pr(float x) {
    cout << x;
  }
  void pr(double x) {
    cout << x;
  }
  void pr(long double x) {
    cout << x;
  }
  void pr(char x) {
    cout << x;
  }
  void pr(const char * x) {
    cout << x;
  }
  void pr(const string & x) {
    cout << x;
  }
  void pr(bool x) {
    pr(x ? "true" : "false");
  }

  template < class T1, class T2 > void pr(const pair < T1, T2 > & x);
  template < class T > void pr(const T & x);

  template < class T, class...Ts > void pr(const T & t,
    const Ts & ...ts) {
    pr(t);
    pr(ts...);
  }
  template < class T1, class T2 > void pr(const pair < T1, T2 > & x) {
    pr("{", x.f, ", ", x.s, "}");
  }
  template < class T > void pr(const T & x) {
    pr("{"); // const iterator needed for vector<bool>
    bool fst = 1;
    for (const auto & a: x) pr(!fst ? ", " : "", a), fst = 0;
    pr("}");
  }

  void ps() {
    pr("\n");
  } // print w/ spaces
  template < class T, class...Ts > void ps(const T & t,
    const Ts & ...ts) {
    pr(t);
    if (sizeof...(ts)) pr(" ");
    ps(ts...);
  }

  void pc() {
    cout << "]" << endl;
  } // debug w/ commas
  template < class T, class...Ts > void pc(const T & t,
    const Ts & ...ts) {
    pr(t);
    if (sizeof...(ts)) pr(", ");
    pc(ts...);
  }
  #define dbg(x...) pr("[", #x, "] = ["), pc(x);
}

#ifdef LOCAL
using namespace output;
#endif

set<int> htree[4 * MX], vtree[4 * MX];

int A, B;

void update(int v, int l, int r, int ul, int ur, int x, int t) {
    if (ul > r || ur < l) {
        return;
    } else if(l >= ul && r <= ur) {
        if (!t) {
            htree[v].insert(x);
        } else {
            vtree[v].insert(x);
        }
        return;
    } else {
        int m = (l + r) / 2;
        update(2 * v + 1, l, m, ul, ur, x, t);
        update(2 * v + 2, m + 1, r, ul, ur, x, t);
        return;
    }
}

set<int> query(int v, int l, int r, int qi, int t) {
    set<int> curr;
    if (!t) {
        for (auto &x : htree[v]) curr.insert(x);
    } else {
        for (auto &x : vtree[v]) curr.insert(x);
    }
    if (l == r) {
        return curr;
    } else {
        int m = (l + r) / 2;
        if (m >= qi) {
            set<int> lft = query(2 * v + 1, l, m, qi, t); 
            for (auto x : lft) curr.insert(x);
        } else {
            set<int> rgt = query(2 * v + 2, m + 1, r, qi, t);
            for (auto x : rgt) curr.insert(x);
        }
        return curr;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> A >> B;

    update(0, 0, A, 0, A, 0, 0);
    update(0, 0, A, 0, A, B, 0);
    update(0, 0, B, 0, B, 0, 1);
    update(0, 0, B, 0, B, A, 1);

    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        int x, y, d; cin >> x >> y >> d;
        d--;
        array<int, 4> cans;
        set<int> ud = query(0, 0, A, x, 0);
        set<int> lr = query(0, 0, B, y, 1);
        // dbg(ud, lr);
        cans[0] = *ud.lower_bound(y), cans[1] = *(--ud.lower_bound(y));
        cans[2] = *lr.lower_bound(x), cans[3] = *(--lr.lower_bound(x));
        // dbg(cans);
        ll area = 0;
        ll area2 = 0;
        if (!d) {
            area = (cans[0] - y) * (cans[2] - cans[3]);
            area2 = (y - cans[1]) * (cans[2] - cans[3]);
            update(0, 0, A, cans[3], cans[2], y, 0);
        }
        else {
            area = (cans[2] - x) * (cans[0] - cans[1]);
            area2 = (x - cans[3]) * (cans[0] - cans[1]);
            update(0, 0, B, cans[1], cans[0], x, 1);
        }
        if (area > area2) swap(area, area2);
        cout << area << " " << area2 << '\n';
    }
}

# Verdict Execution time Memory Grader output
1 Correct 34 ms 38016 KB Output is correct
2 Correct 29 ms 38016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 57 ms 38392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5078 ms 39164 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5092 ms 38996 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5093 ms 39164 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5086 ms 43428 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5096 ms 44716 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5097 ms 44848 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5075 ms 45224 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5065 ms 45816 KB Time limit exceeded
2 Halted 0 ms 0 KB -