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

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>
            久久精品成人一区二区三区| 欧美不卡在线视频| 久久九九99视频| 性色av一区二区三区在线观看 | 一区二区三区在线免费播放| 国产一区视频观看| 欧美大片网址| 欧美资源在线| 欧美劲爆第一页| 亚洲主播在线播放| 亚洲一区精品电影| 西西裸体人体做爰大胆久久久| 欧美 日韩 国产在线| 欧美日本乱大交xxxxx| 亚洲美女在线一区| 国产精品免费网站| 久久爱另类一区二区小说| 亚洲第一精品夜夜躁人人爽| 午夜国产欧美理论在线播放| 91久久精品美女高潮| 亚洲免费视频网站| 性久久久久久久久| 亚洲欧美www| 中文一区在线| 亚洲欧美日韩成人高清在线一区| 性一交一乱一区二区洋洋av| 国产午夜精品久久| 午夜精品免费| 欧美有码视频| 久久精品99国产精品日本| 久久五月婷婷丁香社区| 中日韩美女免费视频网站在线观看| 香蕉av777xxx色综合一区| 国产私拍一区| 亚洲一区视频在线观看视频| 欧美国产精品人人做人人爱| 日韩午夜视频在线观看| 一区二区三区四区五区视频| 在线天堂一区av电影| 亚洲女同精品视频| 亚洲在线观看视频| 久久国产精品一区二区| 另类图片国产| 99国产精品视频免费观看一公开| 欧美一区二粉嫩精品国产一线天| 亚洲欧美日韩精品综合在线观看| 国产精品亚洲综合色区韩国| 国产一区二区三区久久久| 亚洲第一在线综合网站| 亚洲小视频在线观看| 欧美a级一区| 欧美国产日韩免费| 一区二区三区久久网| 久久精品成人| 国产精品福利网| 亚洲国产导航| 亚洲一区二区三区三| 欧美成人午夜剧场免费观看| 亚洲免费黄色| 麻豆精品一区二区av白丝在线| 亚洲免费影院| 欧美华人在线视频| 狠狠色狠狠色综合日日tαg| 亚洲欧美国产高清va在线播| 欧美77777| 欧美jizz19hd性欧美| 亚洲一区精品在线| 欧美韩日高清| 亚洲韩日在线| 亚洲一区在线直播| 久久不见久久见免费视频1| 亚洲理论在线观看| 欧美国产91| 在线日韩电影| 久久男人资源视频| 性欧美18~19sex高清播放| 欧美精品一区二| 亚洲国产日韩欧美综合久久 | 翔田千里一区二区| 久久精品欧美| 性做久久久久久免费观看欧美| 亚洲精品午夜| 欧美精品福利视频| 亚洲精品视频免费| 亚洲免费在线视频一区 二区| 先锋资源久久| 国产精品美女黄网| 久久精品系列| 免费成人毛片| 亚洲欧美日韩国产一区| 久久精品二区亚洲w码| 亚洲欧洲视频| 国产一区在线免费观看| 欧美成年人视频网站| 日韩午夜电影在线观看| 亚洲图色在线| 曰韩精品一区二区| 一区二区毛片| 亚洲国产精品成人精品| 在线一区欧美| 亚洲国产精品久久久久婷婷老年| 亚洲欧美国产精品专区久久| 午夜欧美不卡精品aaaaa| 亚洲国产精品激情在线观看| 亚洲精品一区二区三区在线观看| 久久美女性网| 亚洲婷婷免费| 免费成人在线视频网站| 久久aⅴ国产紧身牛仔裤| 欧美精品国产| 免费观看成人网| 国产精品亚洲激情| 日韩天堂av| 亚洲欧洲另类| 久久婷婷国产麻豆91天堂| 亚洲深爱激情| 欧美韩国日本一区| 欧美成人69| 狠狠色伊人亚洲综合成人| 亚洲特级片在线| 亚洲深夜影院| 欧美精品免费观看二区| 欧美aⅴ99久久黑人专区| 国产一区二区三区不卡在线观看| 欧美中文字幕在线视频| 欧美岛国在线观看| 久久久久久国产精品一区| 欧美成人国产一区二区 | 曰韩精品一区二区| 亚洲一区二区视频在线观看| 日韩视频免费在线观看| 麻豆久久久9性大片| 免费在线观看精品| 国产日韩欧美成人| 亚洲欧美日韩天堂| 久久国产精品一区二区三区| 国产伦精品一区二区三区视频孕妇| 午夜精品成人在线| 欧美日韩一区自拍| 一区二区三区欧美日韩| 中文一区字幕| 国产精品亚洲аv天堂网| 亚洲欧美日韩人成在线播放| 久久福利视频导航| 国产一区二区三区免费不卡| 欧美在线视频a| 麻豆久久精品| 亚洲高清自拍| 亚洲欧洲在线免费| 国产精品亚洲视频| 午夜一级久久| 亚洲在线观看视频网站| 欧美激情影院| 亚洲免费观看视频| 亚洲欧美国产高清va在线播| 国产精品久久久久久久久| 亚洲永久在线观看| 久久综合一区二区三区| 亚洲高清不卡| 欧美日韩一级黄| 午夜免费在线观看精品视频| 美日韩免费视频| 99re66热这里只有精品3直播| 欧美精品一区二区三| 国产精品美女久久久| 亚洲欧美日韩久久精品| 久久亚洲一区二区| 国产专区欧美精品| 欧美成人精品不卡视频在线观看| 亚洲午夜av电影| 国产精品久久久久久久久久直播| 久久精品导航| 国产一区深夜福利| 欧美日韩成人综合| 亚洲亚洲精品三区日韩精品在线视频| 精品白丝av| 欧美精品在线网站| 久久激五月天综合精品| 最新精品在线| 香蕉成人伊视频在线观看| 伊伊综合在线| 国产精品久久久爽爽爽麻豆色哟哟| 亚洲靠逼com| 欧美视频在线观看视频极品| 亚洲欧美怡红院| 亚洲大片一区二区三区| 午夜影视日本亚洲欧洲精品| 亚洲二区视频在线| 国产精品久久久一区二区| 两个人的视频www国产精品| 在线一区二区日韩| 欧美承认网站| 亚洲欧美一级二级三级| 亚洲美女尤物影院| 狠狠色综合网站久久久久久久| 亚洲欧美三级在线| 亚洲区国产区| 欧美成人免费全部| 久久另类ts人妖一区二区| 亚洲欧美综合网|