BZOJ 3524: [POI2014]KUR-Couriers
2018-06-17 20:52:52来源:未知 阅读 ()
[POI2014]KUR-Couriers
题目描述
Byteasar works for the BAJ company, which sells computer games.
The BAJ company cooperates with many courier companies that deliver the games sold by the BAJ company to its customers.
Byteasar is inspecting the cooperation of the BAJ company with the couriers.
He has a log of successive packages with the courier company that made the delivery specified for each package.
He wants to make sure that no courier company had an unfair advantage over the others.
If a given courier company delivered more than half of all packages sent in some period of time, we say that it dominated in that period.
Byteasar wants to find out which courier companies dominated in certain periods of time, if any.
Help Byteasar out!
Write a program that determines a dominating courier company or that there was none.
给一个数列,每次询问一个区间内有没有一个数出现次数超过一半
输入输出格式
输入格式:
The first line of the standard input contains two integers, and (), separated by a single space, that are the number of packages shipped by the BAJ company and the number of time periods for which the dominating courier is to be determined, respectively.
The courier companies are numbered from to (at most) .
The second line of input contains integers, (), separated by single spaces; is the number of the courier company that delivered the -th package (in shipment chronology).
The lines that follow specify the time period queries, one per line.
Each query is specified by two integers, and (), separated by a single space.
These mean that the courier company dominating in the period between the shipments of the -th and the -th package, including those, is to be determined.
In tests worth of total score, the condition holds, and in tests worth of total score .
输出格式:
The answers to successive queries should be printed to the standard output, one per line.
(Thus a total of lines should be printed.) Each line should hold a single integer: the number of the courier company that dominated in the corresponding time period, or if there was no such company.
输入输出样例
7 5 1 1 3 2 3 4 3 1 3 1 4 3 7 1 7 6 6
1 0 3 0 4
说明
给一个数列,每次询问一个区间内有没有一个数出现次数超过一半
题解:
就是一个主席树模板。。
1 #include<bits/stdc++.h> 2 using namespace std; 3 4 const int maxn=5e5+5; 5 6 struct node{ 7 int sum,l,r; 8 }t[maxn*21]; 9 int n,m,root[maxn],cnt=1; 10 11 void bt(int &now,int x,int l,int r) 12 { 13 t[cnt++]=t[now]; 14 now=cnt-1; 15 t[now].sum++; 16 if(l==r) 17 return ; 18 int mid=(l+r)>>1; 19 if(x<=mid) 20 bt(t[now].l,x,l,mid); 21 else 22 bt(t[now].r,x,mid+1,r); 23 } 24 25 int query(int i,int j,int x,int l,int r) 26 { 27 if(l==r) 28 return l; 29 int mid=(l+r)>>1; 30 if(2*(t[t[j].l].sum-t[t[i].l].sum)>x) 31 return query(t[i].l,t[j].l,x,l,mid); 32 if(2*(t[t[j].r].sum-t[t[i].r].sum)>x) 33 return query(t[i].r,t[j].r,x,mid+1,r); 34 return 0; 35 } 36 37 int main() 38 { 39 scanf("%d%d",&n,&m); 40 root[0]=0; 41 for(int i=1;i<=n;i++) 42 { 43 int x; 44 scanf("%d",&x); 45 root[i]=root[i-1]; 46 bt(root[i],x,1,n); 47 } 48 for(int i=1;i<=m;i++) 49 { 50 int l,r; 51 scanf("%d%d",&l,&r); 52 printf("%d\n",query(root[l-1],root[r],r-l+1,1,n)); 53 } 54 return 0; 55 }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- bzoj3569 DZY Loves Chinese II 2020-05-25
- bzoj4036 [HAOI2015]按位或 2020-04-26
- 「BZOJ4173」数学 2020-01-15
- bzoj3944 Sum 2019-12-25
- BZOJ1008: [HNOI2008]越狱(快速幂) 2019-08-26
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash