zoukankan      html  css  js  c++  java
  • Codeforces 260E Dividing Kingdom 线段树

    Dividing Kingdom

    9!枚举, 码就完事了。

    #include<bits/stdc++.h>
    #define LL long long
    #define LD long double
    #define ull unsigned long long
    #define fi first
    #define se second
    #define mk make_pair
    #define PLL pair<LL, LL>
    #define PLI pair<LL, int>
    #define PII pair<int, int>
    #define SZ(x) ((int)x.size())
    #define ALL(x) (x).begin(), (x).end()
    #define fio ios::sync_with_stdio(false); cin.tie(0);
    
    using namespace std;
    
    const int N = 2e5 + 7;
    const int inf = 0x3f3f3f3f;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const int mod = 998244353;
    const double eps = 1e-8;
    const double PI = acos(-1);
    
    template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;}
    template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < 0) a += mod;}
    template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;}
    template<class T, class S> inline bool chkmin(T& a, S b) {return a > b ? a = b, true : false;}
    
    int n, totx, toty, hsx[N], hsy[N], prex[N], prey[N];
    int x[N], y[N];
    int a[N];
    
    #define lson l, mid, rt << 1
    #define rson mid + 1, r, rt << 1 | 1
    struct SegmentTree {
        vector<int> y[N << 2];
        void update(int X, int Y, int l, int r, int rt) {
            y[rt].push_back(Y);
            if(l == r) return;
            int mid = l + r >> 1;
            if(X <= hsx[mid]) update(X, Y, lson);
            else update(X, Y, rson);
        }
        void Sort(int l, int r, int rt) {
            sort(ALL(y[rt]));
            if(l == r) return;
            int mid = l + r >> 1;
            Sort(lson); Sort(rson);
        }
        int query(int X1, int X2, int Y1, int Y2, int l, int r, int rt) {
            if(hsx[l] > X2 || hsx[r] < X1 || X1 > X2 || Y1 > Y2) return 0;
            if(X1 <= hsx[l] && hsx[r] <= X2) {
                return upper_bound(ALL(y[rt]), Y2) - lower_bound(ALL(y[rt]), Y1);
            }
            int mid = l + r >> 1;
            return query(X1, X2, Y1, Y2, lson) + query(X1, X2, Y1, Y2, rson);
        }
        int getCnt(int X1, int X2, int Y1, int Y2) {
            return query(X1, X2, Y1, Y2, 1, totx, 1);
        }
    } Tree;
    
    
    void print(int x) {
        if(x & 1) printf("%d.5", x / 2);
        else printf("%d.0", x / 2);
    }
    
    const int MAX = 2000000010;
    
    int main() {
        scanf("%d", &n);
        for(int i = 1; i <= n; i++) {
            scanf("%d%d", &x[i], &y[i]);
            x[i] *= 2; y[i] *= 2;
            hsx[++totx] = x[i];
            hsy[++toty] = y[i];
        }
        for(int i = 1; i <= 9; i++) scanf("%d", &a[i]);
    
        sort(hsx + 1, hsx + 1 + totx);
        totx = unique(hsx + 1, hsx + 1 + totx) - hsx - 1;
        sort(hsy + 1, hsy + 1 + toty);
        toty = unique(hsy + 1, hsy + 1 + toty) - hsy - 1;
    
        for(int i = 1; i <= n; i++) {
            Tree.update(x[i], y[i], 1, totx, 1);
            prex[lower_bound(hsx + 1, hsx + 1 + totx, x[i]) - hsx]++;
            prey[lower_bound(hsy + 1, hsy + 1 + toty, y[i]) - hsy]++;
        }
        
        Tree.Sort(1, totx, 1);
    
        for(int i = 1; i <= totx; i++) prex[i] += prex[i - 1];
        for(int i = 1; i <= toty; i++) prey[i] += prey[i - 1];
        
        sort(a + 1, a + 10);
        int posx, posy;
        int X1, X2, Y1, Y2;
        do {
            int r1 = a[1] + a[2] + a[3];
            int r2 = a[4] + a[5] + a[6];
            int r3 = a[7] + a[8] + a[9];
            int c1 = a[1] + a[4] + a[7];
            int c2 = a[2] + a[5] + a[8];
            int c3 = a[3] + a[6] + a[9];
    
            posx = lower_bound(prex + 1, prex + 1 + totx, r1) - prex;
            if(posx > totx || prex[posx] != r1) continue; X1 = hsx[posx] + 1;
            
            posx = lower_bound(prex + 1, prex + 1 + totx, r1 + r2) - prex;
            if(posx > totx || prex[posx] != r1 + r2) continue; X2 = hsx[posx] + 1;
            
            posx = lower_bound(prex + 1, prex + 1 + totx, r1 + r2 + r3) - prex;
            if(posx > totx || prex[posx] != r1 + r2 + r3) continue;
    
            posy = lower_bound(prey + 1, prey + 1 + toty, c1) - prey;
            if(posy > toty || prey[posy] != c1) continue; Y1 = hsy[posy] + 1;
            
            posy = lower_bound(prey + 1, prey + 1 + toty, c1 + c2) - prey;
            if(posy > toty || prey[posy] != c1 + c2) continue; Y2 = hsy[posy] + 1;
            
            posy = lower_bound(prey + 1, prey + 1 + toty, c1 + c2 + c3) - prey;
            if(posy > toty || prey[posy] != c1 + c2 + c3) continue;
    
            if(Tree.getCnt(-MAX, X1, -MAX, Y1) != a[1]) continue;if(Tree.getCnt(-MAX, X1, Y2, MAX) != a[3]) continue;if(Tree.getCnt(X2, MAX, -MAX, Y1) != a[7]) continue;if(Tree.getCnt(X2, MAX, Y2, MAX) != a[9]) continue;
    
            print(X1); putchar(' '); print(X2); puts("");
            print(Y1); putchar(' '); print(Y2); puts("");
            return 0;
        } while(next_permutation(a + 1, a + 10));
        puts("-1");
        return 0;
    }
    
    /*
    */
  • 相关阅读:
    《Expert .NET 2.0 IL Assembler》 译者笔记 2
    游戏大厅升级日记 第2天
    《Metadata Tables》 Authors
    随便写写,蛮有趣的
    《Metadata Tables》 Introduction
    Oracle跨数据库的数据操作
    要换工作环境了
    javascript中几种操作打印的方法
    Datagrid中实现单选功能
    C#中利用Oracle事务删除表
  • 原文地址:https://www.cnblogs.com/CJLHY/p/10897601.html
Copyright © 2011-2022 走看看