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)
 

Input
There are multiple test cases.

The first line of each case contains a integer n — the number of operations(1<=n<=2105,n<=7105)

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.
 

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.
 

Sample Input
30 00 30 150 10 01 10 10 0
 

Sample Output
Case #1:000Case #2:0102
Hint
For 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
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 玩gta4自由城卡怎么办 gta5游戏服务当前不可用怎么办 健身后胳膊变粗怎么办 健身后手臂变粗怎么办 家猫见到我就跑怎么办 走路多了小腿酸痛怎么办 脚有脚气很痒怎么办 地板精油喷多了怎么办 史莱姆泥变硬了怎么办 dnf剑帝命中率低怎么办 无意中讲话伤害了人怎么办 高中上不下去了怎么办 高三坚持不下去怎么办 word点了不保存怎么办 做了ppt没保存怎么办 中班安全教案迷眼了怎么办 美的空调尘满怎么办 高考报名系统密码忘记怎么办 高考理综8题怎么办 高三了语文很差怎么办 高三了语文成绩差怎么办 供太岁初一忘了怎么办 高一英语100多分怎么办 高一孩子英语差怎么办 高考中题目有错别字怎么办 相亲简单自我介绍后不回我怎么办 初中毕业没考上高中怎么办 幼儿园小朋友经常说脏话幼师怎么办 我不想当组长了怎么办 领导让我做组长怎么办 情人抓住把柄敲诈自己老公怎么办 我太看重朋友了怎么办 初中生下面长硬胡子痒怎么办 孩子不爱与人沟通怎么办 初一初二没学好初三怎么办 打印机提示存储已满怎么办 苹果6内存满了怎么办 手机总显示存储空间不足怎么办 我爱她她不爱我怎么办 孩子爱发脾气·父母怎么办 落枕怎么办简单快速的有效方法