HDU 5372 Segment Game
来源:互联网 发布:alpine python 编辑:程序博客网 时间:2024/06/07 11:46
注意到一个很重要的性质:每次添加的线段必定比前面添加的线段长。
所以可以用 左端点>=当前线段左端点的线段数 - 右端点>当前线段右端点的线段数,就是答案。
Segment Game
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 583 Accepted Submission(s): 146
Problem Description
Lillian is a clever girl so that she has lots of fans and often receives gifts from her fans.
One day Lillian gets some segments from her fans Lawson with lengths of 1,2,3... and she intends to display them by adding them to a number line.At the i-th add operation,she will put the segment with length of i on the number line.Every time she put the segment on the line,she will count how many entire segments on that segment.During the operation ,she may delete some segments on the line.(Segments are mutually independent)
One day Lillian gets some segments from her fans Lawson with lengths of 1,2,3... and she intends to display them by adding them to a number line.At the i-th add operation,she will put the segment with length of i on the number line.Every time she put the segment on the line,she will count how many entire segments on that segment.During the operation ,she may delete some segments on the line.(Segments are mutually independent)
Input
There are multiple test cases.
The first line of each case contains a integer n — the number of operations(1<=n<=2∗105 ,∑n <=7∗105 )
Next n lines contain the descriptions of the operatons,one operation per line.Each operation contains two integers a , b.
if a is 0,it means add operation that Lilian put a segment on the position b(|b|<109 ) of the line.
(For the i-th add operation,she will put the segment on [b,b+i] of the line, with length of i.)
if a is 1,it means delete operation that Lilian will delete the segment which was added at the b-th add operation.
The first line of each case contains a integer n — the number of operations(1<=n<=
Next n lines contain the descriptions of the operatons,one operation per line.Each operation contains two integers a , b.
if a is 0,it means add operation that Lilian put a segment on the position b(|b|<
(For the i-th add operation,she will put the segment on [b,b+i] of the line, with length of i.)
if a is 1,it means delete operation that Lilian will delete the segment which was added at the b-th add operation.
Output
For i-th case,the first line output the test case number.
Then for each add operation,ouput how many entire segments on the segment which Lillian newly adds.
Then for each add operation,ouput how many entire segments on the segment which Lillian newly adds.
Sample Input
30 00 30 150 10 01 10 10 0
Sample Output
Case #1:000Case #2:0102HintFor the second case in the sample:At the first add operation,Lillian adds a segment [1,2] on the line.At the second add operation,Lillian adds a segment [0,2] on the line.At the delete operation,Lillian deletes a segment which added at the first add operation.At the third add operation,Lillian adds a segment [1,4] on the line.At the fourth add operation,Lillian adds a segment [0,4] on the line
Source
2015 Multi-University Training Contest 7
#include <bits/stdc++.h>using namespace std;#define prt(k) cerr<<#k" = "<<k<<endltypedef long long ll;const ll inf = 0x3f3f3f3f;const int N = 202002 << 1;/****************/struct Tree{ int tree[N]; int low(int x) { return x & -x; } void clear() { memset(tree,0, sizeof tree); } void add(int p, int x) { if (p<=0) return; for (int i=p;i<N;i+=low(i)) tree[i]+=x; } int sum(int p) { int r = 0; for (int i=p;i>0;i-=low(i)) r += tree[i]; return r; }}TL, TR;/****************/int n;struct data{ int op, id;}a[N];struct P{ int l, r;}p[N];int t[N<<1], tt;int id[N];int main(){ int ca = 1; while (scanf("%d",&n)==1) { int i = 0; for (int i=1;i<=n;i++) scanf("%d%d", &a[i].op, &a[i].id); tt = 0; memset(id, -1, sizeof id); for (int j=1;j<=n;j++) { int op = a[j].op; if (op==0) { ++i; p[i].l = a[j].id; p[i].r = a[j].id + i; id[j] = i; t[tt++] = p[i].l; t[tt++] = p[i].r; } else { ; } } int m = i; sort(t, t+tt); tt = unique(t, t+tt) - t; map<int, int> Lisan; for (int i=0;i<tt;i++) { Lisan[t[i]] = i + 1; } for (int i=1;i<=m;i++) { p[i].l = Lisan[p[i].l]; p[i].r = Lisan[p[i].r]; } TL.clear(); TR.clear(); printf("Case #%d:\n", ca++); for (int i=1;i<=n;i++) { if (a[i].op == 0) { int j = id[i]; int ans = j - 1 - TL.sum(p[j].l - 1); ans -= j - 1 - TR.sum(p[j].r); printf("%d\n", ans); TL.add(p[j].l, 1); TR.add(p[j].r, 1); } if (a[i].op == 1) { int j = a[i].id; TL.add(p[j].l, -1); TR.add(p[j].r, -1); } } } return 0;}
1 0
- HDU 5372 Segment Game
- HDU 5372 Segment Game
- HDU 5372 Segment Game
- HDU 5372 Segment Game
- HDU 5372 Segment Game
- hdu 5372 Segment Game
- HDU 5372 Segment Game 树状数组
- 【树状数组】 HDU 5372 Segment Game
- hdu 5372 Segment Game(树状数组)
- HDU 5372 Segment Game(线段树)
- HDU 5372 - Segment Game(树状数组)
- 【HDU 5372】Segment Game(树状数组)
- HDU 5372 Segment Game 树状数组
- HDU 5372 Segment Game(树状数组)
- HDU 5372 Segment Game(BIT)
- [HDU 5372] Segment Game (树状数组)
- [树状数组] hdu 5372 Segment Game
- HDU 5336 Segment Game
- 写了一个简单的微信公众号(几乎不需要什么基础就能看懂)
- strust2学习
- Sqlserver Merge
- D3.js以及通用JS(JavaScript)读取并解析服务器端JSON的注意事项
- 如何获取函数传入数组的元素个数——谈数组的退化和引用
- HDU 5372 Segment Game
- java.lang.NullPointerException:
- LoadRunner录制脚本,报连接不到服务器的提示信息 :Request Connection: Remote Serve
- ASP.NET-MVC4--Layout母版页面传入数据Model模型
- ThreadLocal理解与使用
- python中进程通信之signal信号
- await/signal/lock实现生产消费者模式
- Activity调用isDestroyed()方法报出,java.lang.NoSuchMethodError
- js获取当前域名、Url、相对路径和参数