cf1323--Count Subrectangles(思维)

题意:http://codeforces.com/contest/1323/problem/B

思路:

先预处理可能的矩阵,用pair配对配好

假设竖着的有n根,横着的有m根,一共n*m个矩形。也就是说每两根都有机会两两结合

那就把单独一根的数量算好,最后相乘就行了

  1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
  2 #include <cstdio>//sprintf islower isupper
  3 #include <cstdlib>//malloc  exit strcat itoa system("cls")
  4 #include <iostream>//pair
  5 #include <fstream>//freopen("C:\\Users\\13606\\Desktop\\Input.txt","r",stdin);
  6 #include <bitset>
  7 //#include <map>
  8 //#include<unordered_map>
  9 #include <vector>
 10 #include <stack>
 11 #include <set>
 12 #include <string.h>//strstr substr strcat
 13 #include <string>
 14 #include <time.h>// srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
 15 #include <cmath>
 16 #include <deque>
 17 #include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
 18 #include <vector>//emplace_back
 19 //#include <math.h>
 20 #include <cassert>
 21 #include <iomanip>
 22 //#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
 23 #include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
 24 using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
 25 //******************
 26 clock_t __START,__END;
 27 double __TOTALTIME;
 28 void _MS(){__START=clock();}
 29 void _ME(){__END=clock();__TOTALTIME=(double)(__END-__START)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;}
 30 //***********************
 31 #define rint register int
 32 #define fo(a,b,c) for(rint a=b;a<=c;++a)
 33 #define fr(a,b,c) for(rint a=b;a>=c;--a)
 34 #define mem(a,b) memset(a,b,sizeof(a))
 35 #define pr printf
 36 #define sc scanf
 37 #define ls rt<<1
 38 #define rs rt<<1|1
 39 typedef pair<int,int> PII;
 40 typedef vector<int> VI;
 41 typedef unsigned long long ull;
 42 typedef long long ll;
 43 typedef double db;
 44 const db E=2.718281828;
 45 const db PI=acos(-1.0);
 46 const ll INF=(1LL<<60);
 47 const int inf=(1<<30);
 48 const db ESP=1e-9;
 49 const int mod=(int)1e9+7;
 50 const int N=(int)1e6+10;
 51 
 52 int cnt;
 53 pair<ll,ll>pri[N];
 54 ll a[N],b[N];
 55 
 56 void go(int x)
 57 {
 58     for(int i=1;i<=cnt;++i)
 59     {
 60         if(pri[i].first<=x)
 61             a[i]+=x+1-pri[i].first;
 62     }
 63 }
 64 void goo(int x)
 65 {
 66     for(int i=1;i<=cnt;++i)
 67     {
 68         if(pri[i].second<=x)
 69             b[i]+=x+1-pri[i].second;
 70     }
 71 }
 72 
 73 int main()
 74 {
 75     ll n,m,k;
 76     cin>>n>>m>>k;
 77     for(ll i=1;i*i<=k;++i)
 78     {
 79         if(k%i==0)
 80         {
 81             pri[++cnt]={i,k/i};
 82             if(k/i!=i)
 83                 pri[++cnt]={k/i,i};
 84         }
 85     }
 86     int cc=0;
 87     for(int i=1;i<=n;++i)
 88     {
 89         int t;
 90         sc("%d",&t);
 91         if(t)
 92             cc++;
 93         else
 94         {
 95             go(cc);
 96             cc=0;
 97         }
 98     }
 99     if(cc)
100         go(cc);
101     cc=0;
102     for(int i=1;i<=m;++i)
103     {
104         int t;
105         sc("%d",&t);
106         if(t)
107             cc++;
108         else
109         {
110             goo(cc);
111             cc=0;
112         }
113     }
114     if(cc)
115         goo(cc);
116     cc=0;
117     ll ans=0;
118     for(int i=1;i<=cnt;++i)
119         ans+=a[i]*b[i];
120     pr("%lld\n",ans);
121     return 0;
122 }
123 
124 /**************************************************************************************/

 

posted @ 2020-03-09 20:36  ZMWLxh  阅读(283)  评论(0编辑  收藏  举报