A

  一道不错的题,虽然大家都觉得是水题,然而蒟蒻我想出来的好慢……Orz alpq

  发现其实就是一个网格图,每一个大块都是同一颜色……横纵坐标互不干扰……

 1 //UOJ Round #8 A
 2 #include<vector>
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<cstdlib>
 6 #include<iostream>
 7 #include<algorithm>
 8 #define rep(i,n) for(int i=0;i<n;++i)
 9 #define F(i,j,n) for(int i=j;i<=n;++i)
10 #define D(i,j,n) for(int i=j;i>=n;--i)
11 using namespace std;
12 typedef long long LL;
13 inline int getint(){
14     int r=1,v=0; char ch=getchar();
15     for(;!isdigit(ch);ch=getchar()) if (ch=='-') r=-1;
16     for(; isdigit(ch);ch=getchar()) v=v*10-'0'+ch;
17     return r*v;
18 }
19 const int N=1e5+10;
20 /*******************template********************/
21 
22 int n,m,x[N],y[N];
23 int bel1[N],bel2[N],cnt1,cnt2;
24 int main(){
25 #ifndef ONLINE_JUDGE
26     freopen("A.in","r",stdin);
27     freopen("A.out","w",stdout);
28 #endif 
29     n=getint(); m=getint();
30     F(i,1,n) x[i]=getint();
31     F(i,1,m) y[i]=getint();
32     int now=x[1];
33     bel1[1]=1; cnt1=1;
34     F(i,2,n){
35         if (x[i]!=now){
36             cnt1++;
37             now=x[i];
38         }
39         bel1[i]=cnt1;
40     }
41     now=y[1]; bel2[1]=1; cnt2=1;
42     F(i,2,m){
43         if (y[i]!=now){
44             cnt2++;
45             now=y[i];
46         }
47         bel2[i]=cnt2;
48     }
49 
50     int Q=getint();
51     F(i,1,Q){
52         int x1=getint(),y1=getint(),x2=getint(),y2=getint();
53         if (x2<x1) swap(x1,x2); if (y2<y1) swap(y1,y2);
54         int t1=min(bel1[x2]-bel1[x1],cnt1-bel1[x2]+bel1[x1]-(x[1]==x[n]));
55         int t2=min(bel2[y2]-bel2[y1],cnt2-bel2[y2]+bel2[y1]-(y[1]==y[m]));
56         printf("%d\n",t1+t2);
57     }
58     return 0;
59 }
View Code

相关文章: