Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <sstream>
- #include <string>
- #include <vector>
- #include <queue>
- #include <set>
- #include <map>
- #include <cstdio>
- #include <cstdlib>
- #include <cctype>
- #include <cmath>
- using namespace std;
- typedef long long LL;
- #define FOR(k,a,b) for(int k(a); k < (b); ++k)
- #define REP(k,a) for(int k=0; k < (a); ++k)
- int calcBF(int x1, int x2, int y1, int y2)
- {
- vector<vector<int> > v(x2+1,vector<int> (y2+1));
- int res=0;
- REP(i,v.size())
- REP(j,v[0].size())
- {
- if(i && j)
- v[i][j]=(v[i-1][j]+v[i][j-1])%2;
- else
- v[i][j]=1;
- if(i>=x1 && j>=y1)
- res+=v[i][j];
- }
- return res;
- }
- int calc(int x,int y,const vector<int>& mv)
- {
- if(!(x*y))
- return 0;
- if(x<y)
- swap(x,y);
- if(y==1)
- return x;
- int tmpy=0,tmpx=0;
- while((1<<(tmpx+1))<=x)
- {
- ++tmpx;
- if((1<<(tmpy+1))<=y)
- {
- ++tmpy;
- }
- }
- int tt=mv[tmpy]*(1<<(tmpx-tmpy))+calc(y%(1<<tmpy),1<<tmpy,mv)*((1<<(tmpx-tmpy)))+calc(x%(1<<tmpy),1<<tmpy,mv);
- if (tmpx!=tmpy)
- tt+=calc(x%(1<<tmpy),y%(1<<tmpy),mv);
- return tt;
- }
- int main()
- {
- vector<int> third(1,1);
- REP(i,20)
- {
- third.push_back(third.back()*3);
- }
- int res=calc(8,5,third);
- cout << calcBF(0,8,0,4) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment