제출 #1356303

#제출 시각아이디문제언어결과실행 시간메모리
1356303Zbyszek99Garden 3 (JOI26_garden)C++20
100 / 100
3447 ms114404 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;

pll rotate_point(pll x)
{
    return {-x.ss,x.ff};
}

struct rect
{
    ll x1,x2,y1,y2,c;
    void rotate()
    {
        pll p1 = {x1,y1};
        pll p2 = {x2,y2};
        p1 = rotate_point(p1);
        p2 = rotate_point(p2);
        x1 = min(p1.ff,p2.ff);
        x2 = max(p1.ff,p2.ff);
        y1 = min(p1.ss,p2.ss);
        y2 = max(p1.ss,p2.ss);
    }
};

struct event
{
    ll x;
    int type,ind;
    bool operator<(const event& other) const
    {
        if(x != other.x) return x < other.x;
        return type < other.type;
    }
};

const int tree_siz = 1024*1024-1;
pll max_[tree_siz+1];
ll oper[tree_siz+1];

void spych(int v)
{
    max_[v*2].ff += oper[v];
    max_[v*2+1].ff += oper[v];
    oper[v*2] += oper[v];
    oper[v*2+1] += oper[v];
    oper[v] = 0;
}

void add_seg(int akt, int p1, int p2, int s1, int s2, ll x)
{
    if(p2 < s1 || p1 > s2) return;
    if(p1 >= s1 && p2 <= s2)
    {
        max_[akt].ff += x;
        oper[akt] += x;
        return;
    }
    spych(akt);
    add_seg(akt*2,p1,(p1+p2)/2,s1,s2,x);
    add_seg(akt*2+1,(p1+p2)/2+1,p2,s1,s2,x);
    max_[akt] = max(max_[akt*2],max_[akt*2+1]);
}

ll xd1,xd2,X;
vector<pll> query_ans[200001];
rect rects[200001];
int n;
bool is_on[200001];

void solve()
{
    map<int,int> mp;
    map<int,int> mp2;
    rep(i,n)
    {
        is_on[i] = 0;
        mp[rects[i].y1] = 1;
        mp[rects[i].y2] = 1;
    }
    int cur = 1;
    forall(it,mp) 
    {
        mp2[cur] = it.ff;
        mp[it.ff] = cur++;
    }
    rep(i,tree_siz+1) oper[i] = 0;
    rep2(i,tree_siz/2+1,tree_siz) max_[i] = {0,i-(tree_siz/2+1)};
    for(int i = tree_siz/2; i >= 1; i--) max_[i] = max(max_[i*2],max_[i*2+1]);
    int cur_time = n-1;
    vector<event> events;
    rep(i,n)
    {
        events.pb({rects[i].x1,1,i});
        events.pb({rects[i].x2+1,-1,i});
    }
    sort(all(events));
    forall(it,events)
    {
        if(it.ind > cur_time) continue;
        is_on[it.ind] ^= 1;
        if(it.type == 1) add_seg(1,0,tree_siz/2,mp[rects[it.ind].y1],mp[rects[it.ind].y2],rects[it.ind].c);
        else add_seg(1,0,tree_siz/2,mp[rects[it.ind].y1],mp[rects[it.ind].y2],-rects[it.ind].c);
        while(max_[1].ff >= X)
        {
            query_ans[cur_time].pb({it.x,mp2[max_[1].ss]});
            if(is_on[cur_time])
            {
                add_seg(1,0,tree_siz/2,mp[rects[cur_time].y1],mp[rects[cur_time].y2],-rects[cur_time].c);
                is_on[cur_time] = 0;
            }
            cur_time--;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //random_start();
    cin >> xd1 >> xd2 >> n >> X;
    rep(i,n) cin >> rects[i].x1 >> rects[i].x2 >> rects[i].y1 >> rects[i].y2 >> rects[i].c;
    rep(d,4)
    {
        solve();
        rep(i,n) rects[i].rotate();
        rep(i,n) forall(it,query_ans[i]) it = rotate_point(it);
    }
    rep(i,n)
    {
        if(siz(query_ans[i]) == 0)
        {
            cout << "0\n";
            continue;
        }
        ll x1 = 1e18;
        ll x2 = -1e18;
        ll y1 = 1e18;
        ll y2 = -1e18;
        forall(it,query_ans[i])
        {
            x1 = min(x1,it.ff);
            x2 = max(x2,it.ff);
            y1 = min(y1,it.ss);
            y2 = max(y2,it.ss);
        }
        cout << (x2-x1+1)*(y2-y1+1) << "\n";
    }
}
#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...