[codeforces 391D2]Supercollider

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   io   for   art   

這題覺得似乎不難的樣子……

但硬是沒有做出來,真是不知說什麼好喵~

注意到沒有兩條共線的線段具有公用點,沒有重合的線段

說明每個十字形最多涉及一個水平線段和一個豎直線段

這說明我們可以二分了:每條線段兩端砍掉delta長度後,有沒有線段有公用點?

很水的掃描線吧~  按 X 軸掃描,先把橫的線段掃進去,再用豎的線段去查詢

但是寫法是很重要的,我說我不用線段樹你信喵?我說我連離散化都不用你信喵?

約大爺教你做人!@Ruchiose 
  1 #include <cstdio>  2 #include <algorithm>  3 #include <set>  4 const int size=100000;  5   6 namespace IOspace  7 {  8     inline int getint()  9     { 10         register int num=0; 11         register char ch=0, last; 12         do last=ch, ch=getchar(); while (ch<‘0‘ || ch>‘9‘); 13         do num=num*10+ch-‘0‘, ch=getchar(); while (ch>=‘0‘ && ch<=‘9‘); 14         if (last==‘-‘) num=-num; 15         return num; 16     } 17     inline void putint(int num, char ch=‘\n‘) 18     { 19         char stack[10]; 20         register int top=0; 21         if (num==0) stack[top=1]=‘0‘; 22         for ( ;num;num/=10) stack[++top]=num%10+‘0‘; 23         for ( ;top;top--) putchar(stack[top]); 24         if (ch) putchar(ch); 25     } 26 } 27  28 struct line 29 { 30     int x, y, l; 31     inline line() {} 32     inline line(int _x, int _y, int _l):x(_x), y(_y), l(_l) {} 33 }; 34 struct node 35 { 36     int type; 37     int x, y1, y2; 38     inline node() {} 39     inline node(int _type, int _x, int _y1, int _y2):type(_type), x(_x), y1(_y1), y2(_y2) {} 40     inline bool operator < (node a) const {return x!=a.x?x<a.x:type*y2>a.type*a.y2;} 41 }; 42  43 int n, m, k; 44 line h[size], s[size]; 45 node q[size]; 46 std::multiset<int> t; 47 inline int max(int x, int y) {return x>y?x:y;} 48 inline void swap(int & a, int & b) {int t=a; a=b; b=t;} 49 inline bool query(int, int); 50 inline bool check(int); 51  52 int main() 53 { 54     n=IOspace::getint(); m=IOspace::getint(); 55     for (int i=0;i<n;i++) s[i].x=IOspace::getint(), s[i].y=IOspace::getint(), s[i].l=IOspace::getint(); 56     for (int i=0;i<m;i++) h[i].x=IOspace::getint(), h[i].y=IOspace::getint(), h[i].l=IOspace::getint(); 57  58     int left=0, right=0, mid; 59     for (int i=0;i<n;i++) right=max(right, s[i].l); 60     while (left+1<right) 61     { 62         mid=(left+right)>>1; 63         if (check(mid)) left=mid; 64         else right=mid; 65     } 66  67     IOspace::putint(left); 68  69     return 0; 70 } 71  72 inline bool query(int l, int r) 73 { 74     return t.lower_bound(l)!=t.upper_bound(r); 75 } 76 inline bool check(int d) 77 { 78     k=0; 79     for (int i=0;i<m;i++) if (h[i].l>=(d<<1)) 80     { 81         q[k++]=node(1, h[i].x+d, h[i].y, 1); 82         q[k++]=node(1, h[i].x+h[i].l-d, h[i].y, -1); 83     } 84     for (int i=0;i<n;i++) if (s[i].l>=(d<<1)) 85         q[k++]=node(0, s[i].x, s[i].y+d, s[i].y+s[i].l-d); 86     std::sort(q, q+k); 87     t.clear(); 88     for (int i=0;i<k;i++) 89     { 90         if (q[i].type) 91         { 92             if (q[i].y2==1) t.insert(q[i].y1); 93             else t.erase(t.find(q[i].y1)); 94         } 95         else 96             if (query(q[i].y1, q[i].y2)) 97                 return true; 98     } 99     return false;100 }
本傻受益匪淺系列

 

只存操作(包括插入、刪除、詢問)真是無比的高大上,跪跪跪

還有那鬼畜的查詢寫法

(set).lower_bound(l)!=(set).upper_bound(r)

可以查詢 [l..r] 中是否有數存在,至於為什麼這樣是對的而不是別的樣子了,大家在紙上畫畫就知道了吧

其實更好理解的是

當 (set).lower_bound(l)==(set).upper_bound(r) 時, [l..r] 中一定沒有數

lower_bound是為了將 l 算入 [l..r] 中,upper_bound(r) 也是為了將 r 算入 [l..r] 中

真是跪跪跪跪跪跪跪跪

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.