Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- using namespace std;
- using ll = long long;
- using ld = long double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- int n;
- vector <int> a;
- int l,r;
- struct tree{
- vector <int> t;
- void bld(){
- int mxn = log2(n);
- cout<<"n mxn = "<<n<<' '<<mxn<<"\n";
- if (pow(2, mxn) < n){
- mxn++;
- }
- mxn = pow(2, mxn);
- t.assign(2 * mxn - 1, 0);
- a.resize(mxn);
- for (int i = 0; i < n; ++i){
- cin>>a[i];
- }
- int id = 2*mxn-2;
- for (int i = mxn-1; i >= 0; --i){
- t[id] = a[i];
- id--;
- }
- for (int i = 2 * mxn - 2; i >= 2; i -= 2){
- t[(i-1)/2] = t[i] + t[i-1];
- }
- }
- void sh(){
- cout<<"tree\n";
- cv(t);
- }
- void req(char x){
- }
- };
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cin>>n;
- tree wrk;
- wrk.bld();
- //wrk.sh();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement