Codeforces 780G Andryusha and Nervous Barriers
来源:互联网 发布:淘宝上回收手机可靠吗 编辑:程序博客网 时间:2024/06/13 04:54
现有一个宽
容易想到一个
我们可以把从同一个位置扔出的小球看作一个集合,那么一个屏障最多会产生两个集合,且会至少减少一个集合,那么最多会有
#include <bits/stdc++.h>using namespace std;const int maxn = 2e5 + 10;const int jyb = 1e9 + 7;struct node{ int l,r; set<int>s;}t[maxn];int tot;struct Barriers{ int h,l,r,s; bool operator < (const Barriers &b) const { if(s == b.s) return h > b.h; return s < b.s; }}b[maxn];map<int,int>haha;int ans[maxn];int h,n,w;int hh,l,r,s;void build(int p,int l,int r){ if(l == r) return; int mid = (l + r) >> 1; t[p].l = ++tot; t[p].r = ++tot; build(t[p].l,l,mid); build(t[p].r,mid+1,r);}void change(int p,int l,int r,int L,int R,int h,int d){ if(L == l && R == r) { if(d == 1) t[p].s.insert(h); else t[p].s.erase(h); return; } int mid = (l + r) >> 1; if(R <= mid) change(t[p].l,l,mid,L,R,h,d); else if(L > mid) change(t[p].r,mid+1,r,L,R,h,d); else { change(t[p].l,l,mid,L,mid,h,d); change(t[p].r,mid+1,r,mid+1,R,h,d); }}int query(int p,int l,int r,int pos){ int res = 0; if(t[p].s.size() > 0) res = *t[p].s.rbegin(); if(l == r) return res; int mid = (l + r) >> 1; if(pos <= mid) res = max(res,query(t[p].l,l,mid,pos)); else res = max(res,query(t[p].r,mid+1,r,pos)); return res;}int main(){ cin >> h >> w >> n; for(int i = 1; i <= n; i++) { scanf("%d%d%d%d",&hh,&l,&r,&s); b[i*2-1].h = hh; b[i*2-1].l = l; b[i*2-1].r = r; b[i*2-1].s = s + hh; b[i*2].h = hh; b[i*2].l = l; b[i*2].r = r; b[i*2].s = hh; haha[hh] = i; } n <<= 1; sort(b+1,b+1+n); build(0,1,w); ans[0] = 1; for(int i = 1; i <= n; i++) { if(b[i].h != b[i].s) { if(b[i].s > h) break; change(0,1,w,b[i].l,b[i].r,b[i].h,-1); } else { int hl,hr; if(b[i].l == 1) { hr = query(0,1,w,b[i].r+1); ans[haha[b[i].h]] = 2 * ans[haha[hr]] % jyb; } else if(b[i].r == w) { hl = query(0,1,w,b[i].l-1); ans[haha[b[i].h]] = 2 * ans[haha[hl]] % jyb; } else { hl = query(0,1,w,b[i].l-1); hr = query(0,1,w,b[i].r+1); ans[haha[b[i].h]] = (ans[haha[hl]] + ans[haha[hr]]) % jyb; } change(0,1,w,b[i].l,b[i].r,b[i].h,1); } } int sum = 0; for(int i = 1; i <= w; i++) { int h = query(0,1,w,i); sum = (sum + ans[haha[h]]) % jyb; } printf("%d\n",sum); return 0;}
#include <bits/stdc++.h>using namespace std;const int maxn = 1e5 + 10;const int jyb = 1e9 + 7;struct group{ int h,x; group(int _h,int _x) { h = _h; x = _x; }};stack<group>s[maxn];struct node{ int l,r,x;}t[maxn << 1];int tot;struct Barriers{ int h,l,r,s; bool operator < (const Barriers &b) const { return h > b.h; }}b[maxn];int h,n,w;void build(int p,int l,int r){ if(l == r) { t[p].x = l; return; } int mid = (l + r) >> 1; t[p].l = ++tot; t[p].r = ++tot; build(t[p].l,l,mid); build(t[p].r,mid+1,r); t[p].x = t[t[p].l].x;}void del(int p,int l,int r,int pos){ int mid = (l + r) >> 1; if(l == r) { s[pos].pop(); return; } int ls = t[p].l; int rs = t[p].r; if(pos <= mid) del(ls,l,mid,pos); else del(rs,mid+1,r,pos); int ll = t[ls].x; int rr = t[rs].x; if(s[rr].empty()) t[p].x = ll; else if(s[ll].empty()) t[p].x = rr; else t[p].x = s[ll].top().h <= s[rr].top().h ? ll : rr;}void add(int p,int l,int r,int pos,const group g){ int mid = (l + r) >> 1; if(l == r) { s[pos].push(g); return; } int ls = t[p].l; int rs = t[p].r; if(pos <= mid) add(ls,l,mid,pos,g); else add(rs,mid+1,r,pos,g); int ll = t[ls].x; int rr = t[rs].x; if(s[rr].empty()) t[p].x = ll; else if(s[ll].empty()) t[p].x = rr; else t[p].x = s[ll].top().h <= s[rr].top().h ? ll : rr;}int query(int p,int l,int r,int L,int R){ int mid = (l + r) >> 1; if(l == L && r == R) return t[p].x; int ls = t[p].l; int rs = t[p].r; if(R <= mid) return query(ls,l,mid,L,R); else if(L > mid) return query(rs,mid+1,r,L,R); else { int ll = query(ls,l,mid,L,mid); int rr = query(rs,mid+1,r,mid+1,R); if(s[rr].empty()) return ll; else if(s[ll].empty()) return rr; else return s[ll].top().h <= s[rr].top().h ? ll : rr; }}int main(){ cin >> h >> w >> n; for(int i = 1; i <= n; i++) scanf("%d%d%d%d",&b[i].h,&b[i].l,&b[i].r,&b[i].s); sort(b+1,b+1+n); build(0,1,w); for(int i = 1; i <= w; i++) s[i].push(group(h+1,1)); for(int i = 1; i <= n; i++) { group p(b[i].h,0); while(1) { int j = query(0,1,w,b[i].l,b[i].r); if(s[j].empty()) break; group tmp = s[j].top(); if(tmp.h > b[i].h + b[i].s) break; del(0,1,w,j); p.x = (p.x + tmp.x) % jyb;; } if(b[i].l == 1) { p.x = (p.x + p.x) % jyb; add(0,1,w,b[i].r+1,p); } else if(b[i].r == w) { p.x = (p.x + p.x) % jyb; add(0,1,w,b[i].l-1,p); } else { add(0,1,w,b[i].l-1,p); add(0,1,w,b[i].r+1,p); } } int sum = 0; for(int i = 1; i <= w; i++) while(!s[i].empty()) { sum = (sum + s[i].top().x) % jyb; s[i].pop(); } printf("%d\n",sum); return 0;}
阅读全文
0 0
- Codeforces 780G Andryusha and Nervous Barriers
- Codeforces 780A-Andryusha and Socks
- Codeforces 780C-Andryusha and Colored Balloons
- CodeForces 780A Andryusha and Socks【水题】
- Codeforces Andryusha and Colored Balloons
- Codeforces 782 Andryusha and Socks
- Codeforces 780C Andryusha and Colored Balloons 搜索dfs
- CodeForces 780C Andryusha and Colored Balloons【DFS】
- codeforces 780-C. Andryusha and Colored Balloons(dfs)
- Codeforces 780C-Andryusha and Colored Balloons dfs
- 【codeforces 782A】Andryusha and Socks
- 【codeforces 782C】Andryusha and Colored Balloons
- codeforces 782c Andryusha and Colored Balloons
- codeforces 782a Andryusha and Socks
- 【Codeforces Round #403】Codeforces 781A Andryusha and Colored Balloons
- Codeforces Round #403 (Div. 2) C. Andryusha and Colored Balloons
- Codeforces 782C Andryusha and Colored Balloons dfs
- Codeforces Round #403 C. Andryusha and Colored Balloons(DFS)
- Android使用Http访问并解析服务器XML数据
- C学习笔记20170820
- Python网络数据采集——BeautifulSoup
- HDU6152-Friend-Graph
- c++类的简单实现
- Codeforces 780G Andryusha and Nervous Barriers
- 编程之美
- es6
- 网络爬虫浅析
- Tesseract-OCR 从编译到集成
- HDU 6153 A Secret(扩展kmp模板题)
- JEESZ RestFul服务介绍
- sqlite3数据库存取和取出图片
- Ubuntu中vsftpd实现不同用户不同权限