Zoj 3633 Alice's present
来源:互联网 发布:论文账务处理程序优化 编辑:程序博客网 时间:2024/05/17 05:14
As a doll master, Alice owns a wide range of dolls, and each ofthem has a number tip on it's back, the tip can be treated as apositive integer. (the number can be repeated). One day, Alicehears that her best friend Marisa's birthday is coming , so shedecides to sent Marisa some dolls for present. Alice puts her dollsin a row and marks them from 1 ton. Each time Alicechooses an interval from i to j in thesequence ( includei and j ) , and thenchecks the number tips on dolls in the interval from right to left.If any number appears more than once , Alice will treat thisinterval as unsuitable. Otherwise, this interval will be treated assuitable.
This work is so boring and it will waste Alice a lot of time. SoAlice asks you for help .
Input
There are multiple test cases. For each test case:
The first line contains an integer n ( 3≤n ≤ 500,000) ,indicate the number of dolls which Aliceowns.
The second line contains n positive integers ,decribe the number tips on dolls. All of them are less than 2^31-1.The third line contains an intergerm ( 1 ≤ m≤ 50,000 ),indicate how many intervals Alice will query. Thenfollowed by m lines, each line contains two integeru,v ( 1≤ u< v≤n ),indicate the left endpoint and right endpoint of theinterval. Process to the end of input.
Output
For each test case:
For each query, If this interval is suitable , print one line"OK". Otherwise, print one line ,the integer which appears morethan once first.
Print an blank line after each case.
Sample Input
51 2 3 1 231 41 53 561 2 3 3 2 141 42 53 64 6
Sample Output
12OK333OK
时间复杂度 nlogn
这个题数据不强,直接用个数组来保存而不用map也能水过
若数据强,它输入的数据 less than 2^31-1,开不了这么大的数组
#include<stdio.h>#include<map>using namespace std;#define MAXN 511111map<int,int>num;int d[MAXN],c[MAXN]; //d数组存储位置,c数组存储数int main(void){ int n,i,tmp,m;// freopen("d:\\in.txt","r",stdin); map<int,int>::iterator a; while(scanf("%d",&n)==1) { d[0]=-1; for(i=1;i<=n;i++) { scanf("%d",&tmp); a=num.find(tmp); if(a!=num.end()) { if(a->second>d[i-1]) { d[i]=a->second; c[i]=a->first; } else { d[i]=d[i-1]; c[i]=c[i-1]; } a->second=i; } else { d[i]=d[i-1]; c[i]=c[i-1]; num.insert(pair<int,int>(tmp,i)); } } scanf("%d",&m); int b1,b2; for(i=1;i<=m;i++) { scanf("%d%d",&b1,&b2); if(d[b2]>=b1) printf("%d\n",c[b2]); else printf("OK\n"); } printf("\n"); num.clear(); } return 0;}
- ZOJ 3633 Alice's present
- ZOJ-3633-Alice's present
- zoj 3633 Alice's present
- Zoj 3633 Alice's present
- zoj 3633 Alice's present
- ZOJ 3633 Alice's present
- ZOJ 3633Alice's present
- zoj 3633 Alice's present
- zoj 3633 Alice's present
- ZOJ-3633-Alice's present
- zoj 3633 Alice's present 线段树
- zoj(3633)Alice‘s present
- ZOJ 3633 Alice's present【线段树】
- ZOJ 3633Alice's present (脑洞题)
- ZOJ 3633 Alice's present (STL set)
- zoj 3633 Alice's present(离线+线段树)
- zoj-3633 Alice's present 离线线段树
- [ZOJ 3633]Alice's present 离线分块/线段树
- 设计模式(3) –建造者模式(Builder)
- 每天学习10句英语-第十五天
- 基于apache的nagios安装与配置
- 基于nginx的nagios安装与配置
- 利用nagios监控本地服务器和远端服务器
- Zoj 3633 Alice's present
- AVC_AAC压制
- nagios监控实例 -- 服务器基本状况监控
- nagios监控实例 -- PostgreSQL监控
- 查找圖像中橢圓輪廓的快速隨機hough變換
- 不規則物體形狀匹配綜述
- 以德服人——合格的产品经理
- nagios监控实例 -- Windows服务器监控
- C# (值类型/应用类型/内存框图)与对象深度/浅度复制/系列化/反系列化)