Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize ("Ofast,unroll-loops")
- #pragma GCC target ("avx2,fma")
- #include<bits/stdc++.h>
- using namespace std;
- //rope
- #define forx(i,a,b) for (int i = a; i < b; i++)
- #define INF 1e9
- #define all(x2) begin(x2),end(x2)
- #define isz(t) ((int)(t.size()))
- #define last(x) (*(x.end()-1))
- #define mod ll(1e9+7)
- #define ft first
- #define sd second
- #define pr pair
- //#define _GLIBCXX_DEBUG 1
- //#define _GLIBCXX_DEBUG_PEDANTIC 1
- //#define _FORTIFY_SOURCE 2
- //#define sh(x) cerr<<#x<<" = "<<x<<'\n'
- //#define debug
- using ll= long long;//
- using ld= long double;
- using ull=unsigned long long;
- template<typename T>
- ostream& print_range(ostream& os,T begin,T end){
- for(auto it=begin;it!=end;++it)
- os<<*it<<' ';
- os<<'\n';
- return os;
- }
- template<typename ...T>
- ostream& operator<<(ostream& os,const vector<T...>&v){
- return print_range(os,v.begin(),v.end());
- }
- string to_string(string s){
- return s;
- }
- template<typename ...Args>
- void printer(Args&&... args) {
- (std::cerr << ... <<( to_string(args)+" ")) << '\n';
- }
- template<typename T, typename... Args>
- void push_back_vec(std::vector<T>& v, Args&&... args)
- {
- (v.push_back(std::forward<Args>(args)), ...);
- }
- template<class ...Args>
- void input(Args &... args) {
- (cin>>...>>args);
- }
- template<typename T>
- T minimum(T x) {
- return x;
- }
- template<typename T, typename... Pack>
- auto minimum(T x, Pack... p) {
- using common = typename std::common_type<T, Pack...>::type;
- return std::min((common) x, (common) minimum(p...));
- }
- template<typename T>
- T maximum(T x) {
- return x;
- }
- template<typename T, typename... Pack>
- auto maximum(T x, Pack... p) {
- using common = typename std::common_type<T, Pack...>::type;
- return std::max((common) x, (common) maximum(p...));
- }
- string operator*(const string &h, int k) {
- string u;
- forx(i, 0, k)u += h;
- return u;
- }
- class seg{
- struct v{
- int inf=-1;
- v* l=nullptr;
- v* r=nullptr;
- };
- v* n;
- public:
- vector<int> arr;
- seg(seg const &d){
- arr=d.arr;
- n=build(0,isz(arr));
- }
- v* get_n(){
- return n;
- }
- seg(const vector<int>&arr){
- this->arr=arr;
- n=build(0,isz(arr));
- }
- v* build(int l,int r){
- if(l>=r)
- return nullptr;
- v* x=new v;
- x->inf=arr[(l+r)/2];
- x->l=build(l,(l+r)/2);
- x->r=build((l+r)/2+1,r);
- return x;
- }
- void pris(){
- vector<vector<int>>f(4*isz(arr),vector<int>(isz(arr)*4,INF));
- pe(0,isz(arr)*2,n,f);
- for(auto& a:f){
- for(int& i:a){
- if(i==INF)
- cout<<' ';
- else
- cout<<i;
- }
- cout<<'\n';
- }
- }
- void pe(int x,int y,v* r,vector<vector<int>>& f){
- f[y][x]=r->inf;
- if(r==n)
- ++y;
- if(r->l!=nullptr){
- pe(x+2,y+1,r->l,f);
- }
- if(r==n)
- y-=2;
- if(r->r!=nullptr){
- pe(x+2,y-1,r->r,f);
- }
- }
- int ct(v* x){
- if(x==nullptr)
- return 0;
- if((x->inf)%2==0)
- return 1+ct(x->l)+ct(x->r);
- return 0+ct(x->l)+ct(x->r);
- }
- };
- void solution() {
- seg a({0,1,2,3,4,5,6,7,8,9,10});
- a.pris();
- cout<<"Number of even elements: "<<a.ct(a.get_n());
- seg b(a);
- }
- int32_t main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- // cout.setf(ios::fixed);
- // cout.precision(15);
- // freopen("input.txt", "r", stdin);
- // freopen("output.txt", "w", stdout);
- solution();
- }
Advertisement
Add Comment
Please, Sign In to add comment