Submission #1012683

#TimeUsernameProblemLanguageResultExecution timeMemory
1012683vjudge1Krave (COI14_krave)C++17
100 / 100
435 ms80208 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define lwb lower_bound
#define upb upper_bound

#define TASKNAME "NAME"

void init()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ///freopen(TASKNAME".INP","r",stdin); freopen(TASKNAME".OUT","w",stdout);
}

const int SZ = 1e5+5;
const ll INF = INT_MAX / 2, MOD = 1e9+7, INFLL = 2e18;
const double epsilon = 1e-3;

int a,b,n;

struct SegTree
{
    set<int> nodes[4*SZ];

    void update(int id, int lo, int hi, int u, int v, int val)
    {
        if(hi < u || lo > v) return;
        if(lo >= u && hi <= v)
        {
            nodes[id].insert(val);
            //cout << "update " << lo << " " << hi << " " << val << '\n';
            return;
        }
        int mid = (lo + hi) / 2;
        update(2*id, lo, mid, u , v, val);
        update(2*id+1, mid+1, hi, u, v, val);
    }

    pii query(int id, int lo, int hi, int x, int y)
    {
        pii res;
        auto it1 = nodes[id].lower_bound(y);
        if(it1 == nodes[id].begin())
        {
            res = { (it1 == nodes[id].end() ? INF : *it1), -INF};
        } else
        {
            auto it2 = it1;
            it2--;
            res = { (it1 == nodes[id].end() ? INF : *it1) , *it2};
        }
        //cout << "query " << lo << " " << hi << " " << res.fi << " " << res.se << '\n';
        if(lo == hi) return res;
        int mid = (lo + hi) / 2;
        pii cur;
        if(x <= mid) cur = query(2*id, lo, mid, x, y);
        else cur = query(2*id+1, mid+1, hi, x, y);
        return {min(res.fi, cur.fi), max(res.se, cur.se) };
    }
};

SegTree seg1, seg2;

int main()
{
    init();
    cin >> a >> b;
    seg1.update(1, 1, a, 1, a, 0);
    seg1.update(1, 1 ,a, 1, a, b);
    seg2.update(1, 1, b, 1, b, 0);
    seg2.update(1, 1, b, 1, b, a);
    cin >> n;
    //n = 1;
    for(int i = 1; i <= n; i++)
    {
        int x,y,d;
        cin >> x >> y >> d;
        pii cur1 = seg1.query(1, 1, a, x, y);
        pii cur2 = seg2.query(1, 1, b, y, x);
        ll a1 = cur1.fi - cur1.se, a2 = cur2.fi - cur2.se;
        //cout << cur1.fi << " " << cur1.se << " - " << cur2.fi << " " << cur2.se << '\n';
        if(d == 1)
        {
            ll res1 = a2 * (cur1.fi - y), res2 = a2 * (y - cur1.se);
            cout << min(res1, res2) << " " << max(res1, res2) << '\n';
            seg1.update(1, 1, a, cur2.se, cur2.fi, y);
        } else
        {
            ll res1 = a1 * (cur2.fi - x), res2 = a1 * (x - cur2.se);
            cout << min(res1, res2) << " " << max(res1, res2) << '\n';
            seg2.update(1, 1, b, cur1.se, cur1.fi, x);
        }
    }
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...