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

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>
            国产精品视频久久一区| 国产综合色在线| 日韩午夜在线| 亚洲黄色一区| 欧美成人精品一区二区三区| 亚洲老板91色精品久久| 99精品欧美一区二区三区| 欧美三日本三级三级在线播放| 亚洲午夜一区二区三区| 亚洲欧美视频在线观看| 一区免费观看视频| 亚洲精品久久久久久一区二区 | 欧美国产欧美亚洲国产日韩mv天天看完整 | 亚洲日本电影| 99精品久久久| 国产一区二区在线观看免费| 欧美高清视频在线观看| 国产精品va在线| 久久免费一区| 欧美金8天国| 欧美一区二区黄色| 麻豆久久久9性大片| 亚洲综合三区| 久久人人97超碰国产公开结果 | 国产精品免费观看视频| 久久亚洲欧美国产精品乐播| 欧美成人三级在线| 欧美影院成人| 欧美大香线蕉线伊人久久国产精品| 亚洲一区精品在线| 久久亚洲精品伦理| 亚洲欧美激情精品一区二区| 麻豆精品在线观看| 亚洲欧美另类在线观看| 男女av一区三区二区色多| 销魂美女一区二区三区视频在线| 欧美14一18处毛片| 久久精品91久久久久久再现| 欧美精品一线| 免费人成精品欧美精品| 国产精品视频yy9299一区| 91久久精品国产91久久性色| 国产有码一区二区| 亚洲视频狠狠| 一区二区三区精品国产| 美女精品一区| 久久综合色影院| 国产日产亚洲精品系列| 夜夜嗨av一区二区三区四季av| 亚洲国产天堂久久综合| 久久精品国产99国产精品| 亚洲欧美韩国| 国产精品www994| 亚洲免费av观看| 亚洲日本va在线观看| 久久精品免费| 久久婷婷久久| 国产婷婷色一区二区三区四区| 一区二区三区久久| 亚洲午夜久久久久久尤物 | 亚洲一区在线视频| 亚洲一区二区三区在线| 欧美三区不卡| 日韩视频免费观看| 在线亚洲伦理| 国产精品xxx在线观看www| 亚洲精品在线观| 一级日韩一区在线观看| 欧美激情一区二区三区在线视频观看| 欧美激情视频免费观看| 亚洲精品日韩在线观看| 欧美福利视频网站| 亚洲精品一区二区三区樱花| 在线视频一区二区| 国产精品久久久久久一区二区三区 | 亚洲深夜福利| 欧美偷拍一区二区| 亚洲一区日韩| 久久久美女艺术照精彩视频福利播放 | 一区二区三区视频在线观看| 亚洲婷婷综合久久一本伊一区| 欧美日韩在线另类| 亚洲影视在线播放| 久久婷婷久久一区二区三区| 亚洲第一狼人社区| 欧美精品www| 国产精品99久久久久久人| 欧美中文字幕在线观看| 激情五月***国产精品| 欧美成人日韩| 亚洲一区二区三区在线| 久久九九免费视频| 亚洲欧洲一区二区在线观看| 欧美日韩国产丝袜另类| 亚洲综合电影| 欧美成人激情视频| 正在播放亚洲一区| 国产在线精品二区| 欧美精品成人一区二区在线观看 | 欧美一区二区三区在线| 欧美国产激情二区三区| 亚洲午夜小视频| 精品99一区二区三区| 欧美久久久久免费| 香蕉视频成人在线观看| 亚洲成色www8888| 欧美亚洲一区在线| 亚洲激情婷婷| 国产午夜亚洲精品不卡| 欧美久久精品午夜青青大伊人| 亚洲一区欧美| 亚洲欧洲一区二区在线播放| 久久激五月天综合精品| 99精品国产在热久久婷婷| 国际精品欧美精品| 欧美午夜不卡视频| 美女尤物久久精品| 欧美伊人久久久久久久久影院| 亚洲精品免费在线播放| 美女日韩欧美| 欧美自拍偷拍午夜视频| 一本色道久久综合亚洲精品不卡| 一区二区三区在线免费视频| 国产精品嫩草久久久久| 欧美日韩小视频| 欧美高清在线播放| 久久久国产精彩视频美女艺术照福利| 亚洲色图制服丝袜| 日韩视频免费观看高清在线视频 | 久久精品五月婷婷| 亚洲一级在线观看| 99日韩精品| 亚洲精品午夜| 亚洲人成网在线播放| 红桃视频欧美| 海角社区69精品视频| 国产精品三级视频| 国产精品久久国产精品99gif| 欧美极品aⅴ影院| 欧美黄色一区二区| 欧美高清在线播放| 欧美国产日韩a欧美在线观看| 久久一区中文字幕| 久久中文在线| 免费观看欧美在线视频的网站| 久久视频这里只有精品| 久久久久网站| 蜜臀av性久久久久蜜臀aⅴ四虎| 久久久久国色av免费观看性色| 久久精品一区二区三区四区 | 99精品视频免费| 9色精品在线| 亚洲精品一区二| 日韩一级在线观看| 在线亚洲高清视频| 午夜亚洲伦理| 久久精品首页| 免费不卡在线视频| 欧美韩日一区二区| 欧美日在线观看| 国产精品一区在线播放| 国产婷婷色一区二区三区| 影音先锋亚洲电影| 亚洲精品视频在线观看免费| 亚洲手机视频| 久久精品123| 麻豆精品视频在线| 亚洲激情精品| 亚洲欧美国产va在线影院| 久久激情综合| 欧美日韩国产免费| 国产亚洲一二三区| 亚洲激情二区| 亚洲欧美日韩综合| 久久亚洲色图| 日韩系列在线| 久久av红桃一区二区小说| 欧美成人性生活| 国产精品一区在线观看| 亚洲国产精品欧美一二99| 亚洲一二三四区| 老色鬼久久亚洲一区二区| 日韩一级免费| 久久久爽爽爽美女图片| 欧美日韩另类在线| 狠狠久久五月精品中文字幕| 亚洲理论电影网| 久久久一区二区三区| 亚洲作爱视频| 久久在线免费| 国产美女精品一区二区三区| 亚洲日本免费| 久久久久亚洲综合| 在线视频你懂得一区| 美女日韩欧美| 国内在线观看一区二区三区 | 国产喷白浆一区二区三区| 亚洲精品欧美日韩专区| 久久精品视频免费观看| 一区二区三区欧美视频|