青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

oyjpArt ACM/ICPC算法程序設計空間

// I am new in programming, welcome to my blog
I am oyjpart(alpc12, 四城)
posts - 224, comments - 694, trackbacks - 0, articles - 6
Minimizing maximizer
Time Limit: 5000MS Memory Limit: 30000K
Total Submissions: 1004 Accepted: 280

Description
The company Chris Ltd. is preparing a new sorting hardware called Maximizer. Maximizer has n inputs numbered from 1 to n. Each input represents one integer. Maximizer has one output which represents the maximum value present on Maximizer's inputs.

Maximizer is implemented as a pipeline of sorters Sorter(i1, j1), ... , Sorter(ik, jk). Each sorter has n inputs and n outputs. Sorter(i, j) sorts values on inputs i, i+1,... , j in non-decreasing order and lets the other inputs pass through unchanged. The n-th output of the last sorter is the output of the Maximizer.

An intern (a former ACM contestant) observed that some sorters could be excluded from the pipeline and Maximizer would still produce the correct result. What is the length of the shortest subsequence of the given sequence of sorters in the pipeline still producing correct results for all possible combinations of input values?

Task
Write a program that:

reads a description of a Maximizer, i.e. the initial sequence of sorters in the pipeline,
computes the length of the shortest subsequence of the initial sequence of sorters still producing correct results for all possible input data,
writes the result.

Input
The first line of the input contains two integers n and m (2 <= n <= 50000, 1 <= m <= 500000) separated by a single space. Integer n is the number of inputs and integer m is the number of sorters in the pipeline. The initial sequence of sorters is described in the next m lines. The k-th of these lines contains the parameters of the k-th sorter: two integers ik and jk (1 <= ik < jk <= n) separated by a single space.

Output
The output consists of only one line containing an integer equal to the length of the shortest subsequence of the initial sequence of sorters still producing correct results for all possible data.

Sample Input

40 6
20 30
1 10
10 20
20 30
15 25
30 40

 

Sample Output

4

 

Hint
Huge input data, scanf is recommended.

Source
Central Europe 2003

//pku1769
/*
 * trival DP dp[i] = dp[j] + 1 (if there is a segment starting from a->i && a <= j)  o(n^2)
 * 考慮到轉移的時候選擇的是一段內的最小dp值,運用點樹可以解決
 */
#include <string.h>
#include <stdio.h>

const int N = 50010;
const int MAXINT = 1000000000;

int n, l;

struct ST {int i,j,m,l,r,c;} st[2*N];
int up, cnt;

void bd(int d, int x, int y) {
 st[d].i = x, st[d].j = y, st[d].m = (x+y)/2, st[d].c = MAXINT;
 if(x < y) {
  st[d].l = ++up; bd(up, x, st[d].m);
  st[d].r = ++up; bd(up, st[d].m+1, y);
 }
}

void ins(int d, int x, int c) {
 if(c < st[d].c)
  st[d].c = c;
 if(st[d].i != st[d].j) {
  if(x <= st[d].m)
   ins(st[d].l, x, c);
  else
   ins(st[d].r, x, c);
 }
}

int getmin(int d, int x, int y) {
 if(x <= st[d].i && y >= st[d].j)
  return st[d].c;
 int min = MAXINT;
 if(x <= st[d].m) {
  int now = getmin(st[d].l, x, y);
  if(now < min) min = now;
 }
 if(y > st[d].m) {
  int now = getmin(st[d].r, x, y);
  if(now < min) min = now;
 }
 return min;
}

int main() {
 int i, a, b;
 up = 0;
 scanf("%d %d ", &l, &n);
 bd(0, 1, l);
 ins(0, 1, 0);
 int max = 0;
 for(i = 0; i < n; ++i) {
  scanf("%d%d", &a, &b);
  if(a < b) {
   int min = getmin(0, a, b-1);
   ins(0, b, min+1);
  }
 }
 printf("%d\n", getmin(0, l, l));
 return 0;
}

Feedback

# re: pku1769 新寫的線段樹(點樹)模版  回復  更多評論   

2007-12-04 16:33 by je
題目沒看懂,能解釋下么?

# re: pku1769 新寫的線段樹(點樹)模版  回復  更多評論   

2007-12-05 11:47 by oyjpart
給定一個線段集,要求選擇其中一個最小的子集來覆蓋整個區域。
要求選定的子集是按照題目給的序來覆蓋。

# re: pku1769 新寫的線段樹(點樹)模版  回復  更多評論   

2008-01-18 08:46 by Littleye
很多測試好像得不到正確答案,例如:
40 4
10 30
14 29
25 30
30 40
答案應該是2,你的程序給的是1000000000(你的初始值)
類似的例子還有不少

# re: pku1769 新寫的線段樹(點樹)模版  回復  更多評論   

2008-01-18 12:40 by oyjpart
你的樣例是無解的,沒有線段覆蓋【0,10】的區間。

# re: pku1769 新寫的線段樹(點樹)模版  回復  更多評論   

2008-01-19 02:33 by Littleye
I understand now. I don't think I understood the problem thoroughly before. Although the problem description doesn't clearly indicate that all the segments given should cover the whole segment(1,N), it is the right situation or else we can't get the right output from the maximizer. Now the problem description says that we can get the right output, so the subsequences given must cover the whole segments. Thanks a lot!

# re: pku1769 新寫的線段樹(點樹)模版  回復  更多評論   

2008-01-19 12:34 by oyjpart
you are welcome

# re: pku1769 新寫的線段樹(點樹)模版  回復  更多評論   

2008-04-18 10:44 by l-y-p
向大牛學習學習,“運用點樹可以解決”,好思想,很好很強大。但是還有一個疑點:在DP的時候應該從小到大進行,但是沒發現你對y坐標進行排序就直接進行,那如果是考慮這樣兩組數據:
10 40
0 10
從10到40先確定到40的DP值為maxint+1,然后再由0~10確定10的值為1,這樣是不是有問題??你的程序我沒調試過,不曉得你是怎么處理的?

# re: pku1769 新寫的線段樹(點樹)模版  回復  更多評論   

2008-04-18 10:58 by l-y-p
果然啊,剛調試了下,直接運行數據:
40 2
10 40
0 10
結果是1000000000,不知道是我沒看清楚還是程序的bug?

# re: pku1769 新寫的線段樹(點樹)模版  回復  更多評論   

2008-04-18 12:19 by oyjpart
題目是有這樣的要求的:
要求選定的子集是按照題目給的序來覆蓋。
嘿嘿 如果我沒有理解錯你的意思的話

# re: pku1769 新寫的線段樹(點樹)模版  回復  更多評論   

2008-04-18 22:02 by l-y-p
汗!
What is the length of the shortest subsequence of the given sequence of sorters
把排序一去掉就AC了,多謝大牛指點,呵呵。
最先還一直在想如果可以排序的話就用不著用點樹了,直接貪心!

# re: pku1769 新寫的線段樹(點樹)模版  回復  更多評論   

2009-08-25 10:39 by demo
你的程序過不了zoj 2451

# re: pku1769 新寫的線段樹(點樹)模版  回復  更多評論   

2009-09-07 23:58 by oyjpart
題目是一樣的嗎

# re: pku1769 新寫的線段樹(點樹)模版  回復  更多評論   

2010-12-01 20:36 by LSK
請仔細讀題。。。ZJU哪個是multi case的
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            免费一级欧美片在线观看| 午夜精品久久久久久久久久久久久| 欧美一区二区在线观看| 国产视频一区在线| 另类人畜视频在线| 欧美成年人视频| 一区二区三区欧美在线| 亚洲一级免费视频| 一区二区三区自拍| 亚洲国产一区二区视频| 欧美精品在线一区二区| 亚洲欧美国产精品桃花| 欧美一区二区免费| 亚洲伦理中文字幕| 亚洲在线日韩| 亚洲国产专区校园欧美| 亚洲美女区一区| 国产一区二区在线观看免费| 亚洲福利视频网| 国产精品日韩欧美综合| 久久婷婷综合激情| 欧美日韩久久精品| 久久视频在线视频| 欧美视频日韩视频| 欧美成黄导航| 国产日韩在线视频| 亚洲精品视频在线观看免费| 国产一级一区二区| 亚洲美女淫视频| 亚洲成在人线av| 亚洲性视频网站| 99re成人精品视频| 久久电影一区| 午夜精品在线观看| 欧美精品123区| 免费观看久久久4p| 国产精品日韩久久久| 亚洲人体偷拍| 亚洲高清视频在线| 欧美在线观看天堂一区二区三区| 一区二区欧美在线| 免费亚洲电影| 久久婷婷av| 国产偷自视频区视频一区二区 | 国产欧美一区二区白浆黑人| 亚洲韩日在线| 在线日韩视频| 欧美中文在线视频| 久久精品盗摄| 国产精品夜夜夜一区二区三区尤| 亚洲黄色有码视频| 亚洲日本电影| 免费一级欧美片在线播放| 久久人人爽人人爽爽久久| 国产精品一区二区三区免费观看 | 新片速递亚洲合集欧美合集| 欧美精品一区二区蜜臀亚洲| 欧美激情一区在线观看| 在线观看精品| 久久免费观看视频| 美脚丝袜一区二区三区在线观看| 韩国三级在线一区| 亚洲一区二区毛片| 欧美日韩视频在线第一区| 亚洲精品午夜精品| 亚洲网站视频| 国产精品久久国产精品99gif| 日韩天堂在线观看| 亚洲女性喷水在线观看一区| 欧美三级午夜理伦三级中文幕| 亚洲精品一区中文| 亚洲欧美视频一区| 国产亚洲成av人在线观看导航| 亚洲欧美日韩在线观看a三区| 欧美专区福利在线| 在线精品国产欧美| 欧美激情一区二区久久久| 亚洲精品久久久久久久久久久 | 国产麻豆9l精品三级站| 欧美一区二区三区免费视频| 久久久亚洲综合| 亚洲国产精品一区二区第四页av| 久久综合九九| 日韩视频亚洲视频| 久久er精品视频| 亚洲国产你懂的| 欧美日韩视频在线第一区| 亚洲欧美精品| 欧美成人精品1314www| 夜夜爽夜夜爽精品视频| 国产欧美日韩精品丝袜高跟鞋 | 麻豆精品视频在线观看视频| 亚洲精品日韩综合观看成人91| 亚洲字幕在线观看| 怡红院av一区二区三区| 欧美日韩国产一级| 欧美在线视频网站| 亚洲国产精品专区久久| 午夜久久电影网| 亚洲精品国产精品国自产观看| 国产精品户外野外| 欧美大片免费久久精品三p | 国内精品久久久久久久影视麻豆 | 亚洲激情视频网站| 亚洲欧美日韩视频二区| 黄色精品网站| 欧美性生交xxxxx久久久| 久久精品五月婷婷| 在线亚洲免费| 亚洲国产毛片完整版 | 亚洲欧美亚洲| 亚洲精品乱码视频| 欧美电影免费观看高清完整版| 亚洲天堂av在线免费| 在线看片日韩| 国产欧美一区二区精品性色| 欧美精品一区二区蜜臀亚洲 | 亚洲欧洲精品天堂一级| 久久久久久久性| 性色av一区二区三区在线观看| 亚洲精品永久免费精品| 在线 亚洲欧美在线综合一区| 国产精品久久一区二区三区| 欧美激情中文不卡| 狂野欧美一区| 久久婷婷一区| 欧美中文字幕不卡| 久久不射网站| 性色av一区二区三区在线观看| 中文日韩欧美| 宅男噜噜噜66国产日韩在线观看| 亚洲国产专区| 亚洲国产精品成人一区二区 | 欧美亚洲一级片| 香蕉免费一区二区三区在线观看| 亚洲深夜福利网站| 在线视频亚洲一区| 亚洲视频一区在线| 亚洲视屏一区| 亚洲淫片在线视频| 午夜视频在线观看一区二区| 亚洲欧美精品suv| 午夜电影亚洲| 欧美专区亚洲专区| 性欧美xxxx大乳国产app| 欧美一级二区| 久久久精品日韩欧美| 老司机精品久久| 蜜桃视频一区| 91久久精品国产91久久性色tv| 亚洲国产精品成人| 99re视频这里只有精品| 中文在线一区| 午夜亚洲伦理| 久久免费精品视频| 欧美二区不卡| 国产精品成人av性教育| 国产日韩久久| 亚洲国产一成人久久精品| 99国产精品久久久久久久成人热| 一本色道久久精品| 性欧美超级视频| 免费成人毛片| 日韩一级大片| 欧美在线一级视频| 欧美精品v国产精品v日韩精品| 欧美体内she精视频在线观看| 国产日韩欧美一区| 亚洲区一区二区三区| 亚洲一区二区影院| 久久亚洲视频| 一区二区三区视频观看| 久久精品综合| 欧美区高清在线| 国产亚洲精品v| 一区二区三区久久精品| 久久国产精品久久w女人spa| 亚洲福利视频一区| 性做久久久久久久久| 欧美高清在线视频| 国产一区二区在线免费观看 | 国内精品美女在线观看| 亚洲最黄网站| 久久伊人亚洲| 亚洲午夜电影在线观看| 欧美成人免费在线视频| 国产亚洲免费的视频看| 亚洲免费观看高清完整版在线观看熊| 先锋影音国产精品| 最新日韩av| 久久婷婷一区| 国产主播精品| 午夜精品www| 日韩视频在线观看国产| 久久一二三国产| 狠狠色综合色区| 性亚洲最疯狂xxxx高清| 99re6热在线精品视频播放速度| 噜噜噜噜噜久久久久久91 | 一区精品在线|