hdu 3627 Giant For
来源:互联网 发布:sql日期时间格式转换 编辑:程序博客网 时间:2024/06/05 20:30
Giant For
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2404 Accepted Submission(s): 536
Problem Description
It is known to us all that YY and LMY are mathematics lovers. They like to find and solve interesting mathematic problems together. Now LMY designs a game for matrix. There is a large matrix whose rows and columns are both not more than 1000000000. And there are three operations for the matrix:
1) add: Mark an element in the matrix. It is guaranteed that the element has not been marked before.
2) remove: Delete an element’s mark. It is guaranteed that the element has been marked before.
3) find: For a given element’s row and column, return a marked element’s row and column, where the marked element’s row and column are larger than the given element’s row and column respectively. If there are multiple solutions, return the element whose row is the smallest; and if there are still multiple solutions, return the element whose column is the smallest. If there is no solution, return -1.
LMY lets YY develop a program to solve the problem. Could you also develop a program to solve the problem?
1) add: Mark an element in the matrix. It is guaranteed that the element has not been marked before.
2) remove: Delete an element’s mark. It is guaranteed that the element has been marked before.
3) find: For a given element’s row and column, return a marked element’s row and column, where the marked element’s row and column are larger than the given element’s row and column respectively. If there are multiple solutions, return the element whose row is the smallest; and if there are still multiple solutions, return the element whose column is the smallest. If there is no solution, return -1.
LMY lets YY develop a program to solve the problem. Could you also develop a program to solve the problem?
Input
The input consists of multiple test cases. For each test case, the first line contains only one integer n. n ≤ 200000. Each of the next n lines describes an operation. There is a blank line between two consecutive test cases.
End of input is indicated by a line containing a zero.
End of input is indicated by a line containing a zero.
Output
Start each test case with "Case #:" on a single line, where # is the case number starting from 1. For each “find” operation, output the result. The format is showed as sample output. There is a blank line between two consecutive test cases.
Sample Input
5add 48 1add 25 69add 88 52remove 25 69add 23 8910add 47 23find 66 83find 27 73add 84 97find 10 58remove 47 23add 41 89remove 41 89find 65 68add 25 410
Sample Output
Case 1:Case 2:-1-184 9784 97把矩阵中的点,离散化成一维的点,然后用线段树乱搞。
#include <stdio.h>#include <string.h>#include <iostream>#include <string>#include <queue>#include <stack>#include <map>#include <set>#include <vector>#include <stdlib.h>#include <algorithm>using namespace std;typedef long long ll;#define rep(i,s,t) for(int i=s;i<t;i++)#define red(i,s,t) for(int i=s-1;i>=t;i--)#define ree(i,now) for(int i=head[now];i!=-1;i=edge[i].next)#define clr(a,v) memset(a,v,sizeof a)#define L t<<1#define R t<<1|1#define MID int mid=(l+r)>>1//#define max(a,b) (a<b?b:a)//#define min(a,b) (a<b?a:b)#define lowbit(x) (x&(-x))#define SQR(a) ((a)*(a))inline int input(){ int ret=0;bool isN=0;char c=getchar(); while(c<'0' || c>'9'){ if(c=='-') isN=1; c=getchar(); } while(c>='0' && c<='9'){ ret=ret*10+c-'0'; c=getchar(); } return isN?-ret:ret;}inline void output(int x){ if(x<0){ putchar('-');x=-x; } int len=0,data[11]; while(x){ data[len++]=x%10;x/=10; } if(!len) data[len++]=0; while(len--) putchar(data[len]+48); putchar('\n');}const int MAXN=200005;struct op{ char op[10]; int a,b;}q[MAXN];int n,to[MAXN],k;map< pair<int,int>,int>mp;map< pair<int,int>,int>::iterator it;int val[MAXN<<2];inline void modefiy(int t,int l,int r,int x,int v){ if(l==r) val[t]=v; else{ MID; if(x<=mid) modefiy(L,l,mid,x,v); else modefiy(R,mid+1,r,x,v); val[t]=max(val[L],val[R]); }}inline pair<int,int> query(int t,int l,int r,int x,int y){ if(val[t]<=y) return make_pair(-1,-1); if(to[r]<=x) return make_pair(-1,-1); if(l==r) return make_pair(to[l],val[t]); MID; pair<int,int> p=query(L,l,mid,x,y); if(p.second==-1) return query(R,mid+1,r,x,y); return p;}int main(){ int ca=1; while(n=input(),n){ if(ca>1) puts(""); printf("Case %d:\n",ca++); k=0,mp.clear(); rep(i,0,n){ scanf("%s%d%d",q[i].op,&q[i].a,&q[i].b); mp[make_pair(q[i].a,q[i].b)]=1; } for(it=mp.begin();it!=mp.end();it++){ (*it).second=(++k); to[k]=(*it).first.first; } clr(val,-1); rep(i,0,n){ if(q[i].op[0]=='a'){ modefiy(1,1,k,mp[make_pair(q[i].a,q[i].b)],q[i].b); } else if(q[i].op[0]=='r'){ modefiy(1,1,k,mp[make_pair(q[i].a,q[i].b)],-1); } else{ pair<int,int> ans=query(1,1,k,q[i].a,q[i].b); if(ans.second==-1) puts("-1"); else printf("%d %d\n",ans.first,ans.second); } } } return 0;}
0 0
- hdu 3627 Giant For
- hdu 3627 Giant For
- hdu 3627 Giant For //线段树
- hdoj 3627 Giant For
- (线段树 + 离散化 ) hdu 3627 Giant For
- hdu 3627 Giant For(map+set模拟)
- 【线段树】 HDOJ 3627 Giant For
- 离散对数,giant-step baby-step,拓展giant-step baby-step (poj 2417, hdu 2815)
- 天津大学2010年区域赛1007 Giant For
- ISCE、GIAnt
- 新增Tao插件,Red Giant 经典特效插件 Trapcode Suite 13 for Win/Mac
- HDU 2815 Mod Tree【扩展Baby Step Giant Step解决离散对数问题】
- hdu 2815Mod Tree (数论题)(baby step giant step 小步大步)
- hdu——2815(数论之Baby Step Giant Step解决离散对数问题)
- HDU 2815 Mod Tree 离散对数 扩展Baby Step Giant Step算法
- HDU Fighting for HDU
- Hdu 2815 Mod Tree + Poj 3243 Clever Y 扩展Baby Step Giant Step 解决离散对数问题
- 高次同余方程:poj 3243+poj 2417+hdu 2815 (Baby Step Giant Step 算法)
- Linux下crontab命令的用法
- NOJ1104素数环——递归
- 频繁分配释放内存导致的性能问题的分析
- matlab 与C 混编时的联合调试
- 笔记——移动对等网络关键技术
- hdu 3627 Giant For
- java反斜杠\的用法
- android 完全退出App
- 《MATLAB面向对象程序设计》
- OpenStack : Nova API 分析
- 论存储IOPS和Throughput吞吐量之间的关系
- leedcode做题总结,题目Binary Tree Preorder Traversal 2013/11/05
- /etc/fstab说明
- TCP/IP 学习笔记之链路层