标签:des style blog color os io 数据 for
题目:
1 #include<set> 2 #include<map> 3 #include<queue> 4 #include<cstdio> 5 #include<cstdlib> 6 #include<cstring> 7 #include<iostream> 8 #include<algorithm> 9 using namespace std; 10 const int N = 100010; 11 #define For(i,n) for(int i=1;i<=n;i++) 12 #define Rep(i,l,r) for(int i=l;i<=r;i++) 13 int q,n,m,op,k,row[N],line[N],Row[N],Line[N]; 14 int T,x,y,c,tx,ty; 15 map< pair<int,int> , int > Ans; 16 17 struct querys{ 18 int x,y,c; 19 }Query[N]; 20 21 int find(int x,int upper,int A[]){ 22 int L = 1 , R = upper; 23 while(R-L>1){ 24 int Mid = (L+R)>>1; 25 if(A[Mid] > x) R = Mid; 26 else L = Mid; 27 } 28 if(A[R]==x) return R; 29 else if(A[L]==x) return L; 30 else return -1; 31 } 32 33 void read(int &v){ 34 int num = 0; char ch = getchar(); 35 while(ch>‘9‘||ch<‘0‘) ch = getchar(); 36 while(ch>=‘0‘&&ch<=‘9‘){ 37 num = num * 10 + ch - ‘0‘; 38 ch = getchar(); 39 } 40 v = num; 41 } 42 43 bool cmp(int A,int B){ 44 return A < B; 45 } 46 47 bool cmp2(int A,int B){ 48 return (A==B); 49 } 50 51 void init(){ 52 Ans.clear(); 53 read(n);read(m);read(k); 54 For(i,k){ 55 read(x);read(y);read(c); 56 Query[i].x = x ; Query[i].y = y; Query[i].c = c; 57 Row[i] = x;Line[i] = y; 58 } 59 sort(Row+1,Row+k+1,cmp); 60 sort(Line+1,Line+k+1,cmp); 61 n = unique(Row+1,Row+k+1,cmp2) - Row - 1; 62 m = unique(Line+1,Line+k+1,cmp2) - Line - 1; 63 For(i,n) row[i] = i; 64 For(i,m) line[i] = i; 65 For(i,k){ 66 int x = find(Query[i].x,n,Row) , y = find(Query[i].y,m,Line); 67 Ans.insert(make_pair(make_pair(x,y),Query[i].c)); 68 } 69 } 70 71 void solve(){ 72 read(q); 73 For(i,q){ 74 read(op);read(tx);read(ty); 75 if(op==1){ 76 x = find(tx,n,Row); y = find(ty,n,Row); 77 } 78 if(op==2){ 79 x = find(tx,m,Line); y = find(ty,m,Line); 80 } 81 if(op==3){ 82 x = find(tx,n,Row); y = find(ty,m,Line); 83 } 84 if(x==-1||y==-1) { 85 if(op==3) puts("0"); 86 continue; 87 } 88 if(op==1) swap(row[x],row[y]); 89 if(op==2) swap(line[x],line[y]); 90 if(op==3){ 91 map< pair<int,int> , int >::iterator tans = Ans.find(make_pair(row[x],line[y])); 92 if(tans==Ans.end()) printf("0\n"); 93 else printf("%d\n",tans->second); 94 } 95 } 96 } 97 98 int main(){ 99 scanf("%d",&T); 100 For(i,T) { 101 printf("Case #%d:\n",i); 102 init(); 103 solve(); 104 } 105 return 0; 106 }
HDU多校联合赛(1007 Magical Forest)模拟题,布布扣,bubuko.com
HDU多校联合赛(1007 Magical Forest)模拟题
标签:des style blog color os io 数据 for
原文地址:http://www.cnblogs.com/kjerome/p/3907807.html