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

oyjpArt ACM/ICPC算法程序設(shè)計空間

// 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)
 * 考慮到轉(zhuǎn)移的時候選擇的是一段內(nèi)的最小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 新寫的線段樹(點樹)模版  回復(fù)  更多評論   

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

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

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

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

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

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

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

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

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 新寫的線段樹(點樹)模版  回復(fù)  更多評論   

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

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

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

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

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

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

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

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

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 新寫的線段樹(點樹)模版  回復(fù)  更多評論   

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

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

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

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

2010-12-01 20:36 by LSK
請仔細(xì)讀題。。。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>
            在线观看欧美日韩| 亚洲国产欧美一区二区三区同亚洲| 欧美xx视频| 欧美激情五月| 亚洲欧美网站| 久久这里只有| 亚洲欧美日本国产专区一区| 久久久精彩视频| 中文国产亚洲喷潮| 久久精品国产第一区二区三区最新章节| 亚洲国产精品一区二区www| 夜夜夜久久久| 亚洲高清激情| 小处雏高清一区二区三区 | 亚洲成人在线网| 国产精品美女久久久久av超清| 免费成人av在线看| 国产农村妇女精品一二区| 亚洲激情综合| 激情婷婷亚洲| 亚洲欧美久久久| 一本色道久久综合亚洲精品不卡 | 欧美凹凸一区二区三区视频| 性色av一区二区三区红粉影视| 欧美不卡在线视频| 久久一区亚洲| 国产精品视频自拍| 日韩视频在线免费| 99视频超级精品| 久久综合中文字幕| 久久一区二区三区四区| 国产欧美日韩专区发布| 中文成人激情娱乐网| 一本大道久久a久久精品综合| 蜜臀av一级做a爰片久久| 老妇喷水一区二区三区| 国产在线高清精品| 欧美在线精品免播放器视频| 久久激情综合| 国产亚洲在线| 久久久精品一品道一区| 久久久精品午夜少妇| 国产婷婷色一区二区三区| 亚洲在线播放| 欧美一级视频| 国产一区二区三区日韩欧美| 午夜久久久久久| 久久精品观看| 一区在线免费观看| 久久综合九色综合久99| 欧美高清视频一二三区| 91久久国产综合久久91精品网站| 麻豆精品91| 亚洲激情在线播放| 国产精品99久久久久久人| 欧美三级电影网| 中文日韩电影网站| 久久精品成人| 国产真实久久| 老司机精品视频一区二区三区| 欧美激情一区二区三区蜜桃视频| 亚洲精品九九| 欧美午夜精品久久久久久超碰| 亚洲午夜国产一区99re久久| 久久aⅴ国产欧美74aaa| 在线精品视频在线观看高清| 欧美激情在线观看| 日韩性生活视频| 欧美一区二区三区免费视频| 红杏aⅴ成人免费视频| 免费观看亚洲视频大全| 日韩视频免费| 久久久久久久97| 亚洲日本在线观看| 国产精品爱啪在线线免费观看| 午夜欧美精品| 亚洲电影观看| 欧美在线亚洲一区| 亚洲人体偷拍| 国产精品一区久久久| 久久一二三国产| 一区二区三区久久| 蜜臀av国产精品久久久久| 中文一区二区| 精品1区2区| 国产精品家教| 久久亚洲综合网| 亚洲视频一二三| 欧美高清hd18日本| 香蕉乱码成人久久天堂爱免费 | 久久精品综合| 亚洲毛片在线免费观看| 韩国在线视频一区| 欧美日本在线播放| 欧美亚洲免费| 亚洲乱码国产乱码精品精天堂 | 欧美精品一区二区三| 亚洲欧美日韩国产一区| 亚洲国产你懂的| 久久久之久亚州精品露出| 99在线热播精品免费99热| 国内精品久久久久伊人av| 欧美日韩国产首页| 久久久久久久久伊人| 亚洲午夜免费视频| 亚洲高清在线观看| 久久全国免费视频| 亚洲伊人第一页| 亚洲乱码精品一二三四区日韩在线| 国产日韩精品一区二区| 欧美日韩免费高清一区色橹橹| 久久国产精品久久国产精品 | 在线亚洲高清视频| 依依成人综合视频| 国产日韩欧美二区| 国产精品乱码一区二三区小蝌蚪| 欧美高清在线一区| 久久久噜噜噜久久中文字免| 亚洲欧美日韩国产一区二区| 亚洲精品一区二区三区四区高清| 欧美激情精品久久久久久| 久久亚洲春色中文字幕| 欧美一区国产二区| 亚洲免费视频在线观看| 野花国产精品入口| 亚洲精品视频在线观看网站| 亚洲二区三区四区| 亚洲大胆人体在线| 一区在线免费| 伊人色综合久久天天| 伊人精品成人久久综合软件| 很黄很黄激情成人| 精品91在线| 亚洲电影欧美电影有声小说| 在线不卡中文字幕播放| 在线日韩一区二区| 在线成人免费观看| 亚洲第一视频网站| 亚洲人成网站999久久久综合| 亚洲国产欧美日韩另类综合| 亚洲国产精品一区二区www在线| 亚洲国产另类精品专区| 亚洲欧洲一级| 一区二区欧美在线观看| 一区二区三区成人| 亚洲一区二区三区乱码aⅴ蜜桃女| 在线综合欧美| 校园春色国产精品| 欧美在线免费视频| 久久综合色影院| 欧美黄色大片网站| 亚洲日本无吗高清不卡| 日韩午夜精品| 亚洲欧美日韩精品久久亚洲区| 欧美一级专区| 久久综合久久综合这里只有精品| 欧美成人免费小视频| 欧美日韩在线视频首页| 国产精品入口| 在线播放中文字幕一区| 夜色激情一区二区| 午夜视频在线观看一区二区三区| 久久久久se| 亚洲国产女人aaa毛片在线| 99人久久精品视频最新地址| 性久久久久久久久| 亚洲免费福利视频| 亚洲一区二区视频在线| 久久精品国产一区二区三区| 欧美激情四色| 国产精品一区2区| 在线观看视频一区| 日韩视频在线免费观看| 先锋影音国产精品| 欧美国产精品人人做人人爱| 一区二区免费在线播放| 久久久999成人| 欧美日韩一区二区高清| 狠狠88综合久久久久综合网| 夜夜爽av福利精品导航 | 欧美日产在线观看| 国产精品一区二区久激情瑜伽| 在线观看亚洲一区| 亚洲一区bb| 女仆av观看一区| 在线综合亚洲欧美在线视频| 久久国产精品毛片| 欧美三日本三级少妇三99| 狠狠久久亚洲欧美| 亚洲香蕉在线观看| 欧美成年网站| 欧美一区不卡| 欧美色精品天天在线观看视频| 狠狠色狠狠色综合系列| 亚洲欧美日韩精品在线| 亚洲国产精品成人综合色在线婷婷 | 免费亚洲视频| 国产日韩欧美一区二区三区在线观看 | 欧美成人免费观看| 亚洲欧美电影在线观看|