malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long int MOD = (long long int)1e9 + 7;   long long int powmod(long long int a, long long int b) {     long long int res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % MOD;       a = (a * a) % MOD;       b = b >> 1;     }     return res % MOD;   }   vector<vector<long long int> > G;   void solve(long long int testnum) {     long long int n, m;     cin >> n >> m;     G.resize(n + 1);     vector<long long int> tt(n + 1, 0);     for (long long int i = 0; i < m; i++) {       long long int a, b;       cin >> a >> b;       G[a].push_back(b);       G[b].push_back(a);     }     vector<pair<long long int, long long int> > bc;     for (long long int i = 1; i <= n; i++) {       long long int temp;       cin >> temp;       bc.push_back(make_pair(temp, i));     }     sort(bc.begin(), bc.end());     long long int check = 0;     for (long long int i = 0; i < bc.size(); i++) {       tt[bc[i].second] = bc[i].first;       vector<long long int> naap;       for (long long int j = 0; j < G[bc[i].second].size(); j++) {         naap.push_back(tt[G[bc[i].second][j]]);       }       if (naap.size() == 0) {         if (bc[i].first != 1) {           check = 1;         }         continue;       }       sort(naap.begin(), naap.end());       for (long long int k = 0; k < naap.size(); k++) {         long long int temp = naap[k];         if (k > 0) {           temp -= naap[k - 1];         }         if (temp > 1) {           check = 1;         }       }       if (naap[naap.size() - 1] != bc[i].first - 1) {         check = 1;       }     }     if (check == 1) {       cout <<  -1 n ;       return;     }     for (long long int i = 0; i < n; i++) {       cout << bc[i].second <<    ;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     for (long long int i = 1; i <= t; i++) {       solve(i);     }   }
#include <bits/stdc++.h>   using namespace std;   struct Update {     int cost, profit;     Update(int cost, int profit) : cost(cost), profit(profit) {}   };   struct CommutativeUndoableDS {     const int MAX_COST = 4000;     vector<vector<int> > stk;     CommutativeUndoableDS() { stk.emplace_back(MAX_COST + 1, 0); }     void addUpdate(Update u) {       int sz = stk.size();       stk.push_back(stk.back());       for (int i = MAX_COST; i >= u.cost; i--) {         stk[sz][i] = max(stk[sz][i], stk[sz - 1][i - u.cost] + u.profit);       }     }     void undoLastUpdate() {       stk.pop_back();       assert(!stk.empty());     }     int bestProfitWith(int budget) { return stk.back()[budget]; }   };   struct QueueUndoDS {     vector<pair<Update, int> > qyu;     CommutativeUndoableDS ds;     void pushBack(pair<Update, int> u) {       ds.addUpdate(u.first);       qyu.push_back(u);     }     void pushBack(Update u) { pushBack(pair<Update, int>(u, 0)); }     void popFront() {       assert(!qyu.empty());       vector<pair<Update, int> > popped[2];       while (!qyu.empty()) {         ds.undoLastUpdate();         popped[qyu.back().second].push_back(qyu.back());         qyu.pop_back();         if (popped[1].size() >= popped[0].size()) break;       }       if (popped[1].empty()) {         for (pair<Update, int> &u : popped[0]) {           u.second = 1;           pushBack(u);         }       } else {         for (int i : {0, 1}) {           reverse(popped[i].begin(), popped[i].end());           for (pair<Update, int> &u : popped[i]) pushBack(u);         }       }       ds.undoLastUpdate();       qyu.pop_back();     }   };   const int MAX_TIME = 20001;   vector<Update> startsAt[MAX_TIME];   vector<Update> endsAt[MAX_TIME];   vector<pair<int, int> > askAt[MAX_TIME];   int ans[MAX_TIME];   int main() {     int n, p;     cin >> n >> p;     while (n--) {       int c, h, t;       cin >> c >> h >> t;       startsAt[t].emplace_back(c, h);       endsAt[t + p - 1].emplace_back(c, h);     }     int q;     cin >> q;     for (int i = 1; i <= q; i++) {       int a, b;       cin >> a >> b;       askAt[a].emplace_back(i, b);     }     QueueUndoDS knapsackQueuUndo;     for (int t = 1; t < MAX_TIME; t++) {       for (Update u : startsAt[t]) {         knapsackQueuUndo.pushBack(u);       }       for (pair<int, int> query : askAt[t]) {         ans[query.first] = knapsackQueuUndo.ds.bestProfitWith(query.second);       }       for (Update u : endsAt[t]) {         knapsackQueuUndo.popFront();       }     }     for (int i = 1; i <= q; i++) {       cout << ans[i] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:200000000 )   const double EPS = 1E-9;   const int INF = 1000000000;   const long long INF64 = (long long)1E18;   const double PI = 3.1415926535897932384626433832795;   string s[110000];   int n, k, z[110][110], dp[1100000];   char buf[110000];   int main() {     scanf( %d%d n , &n, &k);     for (int i = 0; i < (int)(n); i++) {       scanf( %s , buf);       s[i] = buf;     }     for (int i = 0; i < (int)(n); i++)       for (int j = 0; j < (int)(n); j++) {         int ans = 0;         while (ans < (int)s[i].size() && ans < (int)s[j].size() &&                s[i][ans] == s[j][ans])           ans++;         z[i][j] = ans;       }     int res = 0;     for (int msk = 1; msk < (1 << n); msk++) {       int cur;       for (int i = 0; i < (int)(n); i++)         if (msk & (1 << i)) {           cur = i;           break;         }       int val = dp[msk ^ (1 << cur)], cnt = 0;       for (int i = 0; i < (int)(n); i++)         if ((msk & (1 << i)) && i != cur) {           val += z[i][cur];           cnt++;         }       if (cnt + 1 == k) res = max(res, val);       dp[msk] = val;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> adj[3010], vert;   map<int, vector<pair<int, int> > > query[3010];   int ans[400010], vis[3010], in_cycle;   void dfs(int v, int par) {     vis[v] = 1;     if (!in_cycle) vert.push_back(v);     if (query[par].count(v)) {       vector<pair<int, int> > *ptr = &query[par][v];       int vert_size = vert.size();       for (auto p : *ptr) {         ans[p.second] =             ((p.first > vert_size || in_cycle) ? -1 : vert[p.first - 1]);       }     }     for (int i = 0; i < adj[v].size(); ++i) {       int t = adj[v][i];       if (vis[t] == 0)         dfs(t, par);       else if (vis[t] == 1) {         ++in_cycle;         ++vis[t];       }     }     if (v == vert.back()) vert.pop_back();     if (vis[v] > 1)       --in_cycle;     else       vis[v] = 2;   }   int main() {     int n, m, q;     scanf( %d %d %d , &n, &m, &q);     for (int i = 0; i < m; ++i) {       int u, v;       scanf( %d %d , &u, &v);       adj[u].push_back(v);     }     for (int i = 1; i <= n; ++i) {       sort(adj[i].begin(), adj[i].end());     }     for (int i = 0; i < q; ++i) {       int s, t, k;       scanf( %d %d %d , &s, &t, &k);       query[s][t].push_back(make_pair(k, i));     }     for (int i = 0; i < q; ++i) ans[i] = -1;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) vis[j] = 0;       in_cycle = 0;       dfs(i, i);     }     for (int i = 0; i < q; ++i) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 9;   int arr[maxn], ar[maxn];   int main() {     int a, b, c, d, e, f, g, h;     while (cin >> a) {       cin >> e >> f;       for (int i = 1; i <= a; i++) {         cin >> arr[i];       }       for (int i = 1; i <= a; i++) {         cin >> ar[i];       }       g = 1;       for (int i = 1; i < e; i++) {         if (arr[i] != ar[i]) {           g = 0;           break;         }       }       for (int i = f + 1; i <= a; i++) {         if (arr[i] != ar[i]) {           g = 0;           break;         }       }       map<int, int> ma1, ma2;       for (int i = e; i <= f; i++) {         ma1[arr[i]]++;         ma2[ar[i]]++;       }       if (ma1 != ma2) g = 0;       if (!g) {         cout <<  LIE  << endl;       } else {         cout <<  TRUTH  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxm = 6e5 + 5;   int l[maxm], r[maxm];   int c[maxm];   int pos[maxm];   int n, m;   int max(int a, int b) {     if (a > b)       return a;     else       return b;   }   int lowbit(int i) { return i & -i; }   void add(int i, int t) {     while (i < maxm) {       c[i] += t;       i += lowbit(i);     }   }   int ask(int i) {     int ans = 0;     while (i) {       ans += c[i];       i -= lowbit(i);     }     return ans;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       l[i] = r[i] = i;       add(i + m, 1);       pos[i] = i + m;     }     int last = m;     while (m--) {       int x;       cin >> x;       l[x] = 1;       int num = ask(pos[x]);       r[x] = max(r[x], num);       if (num == 1) continue;       add(pos[x], -1);       pos[x] = last;       add(pos[x], 1);       last--;     }     for (int i = 1; i <= n; i++) {       r[i] = max(r[i], ask(pos[i]));     }     for (int i = 1; i <= n; i++) {       cout << l[i] <<     << r[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   int size(T& a) {     return (int)a.size();   }   template <typename T>   T sqr(T a) {     return a * a;   }   int offset;   int f[1000000 * 4 + 10];   int start[27];   int getmask(int l, int r) {     int res = 0;     for (l += offset, r += offset; l <= r; l /= 2, r /= 2) {       if (l % 2 == 1) {         res |= f[l++];       }       if (r % 2 == 0) {         res |= f[r--];       }     }     return res;   }   vector<int> pos[27];   int ans[10000];   map<int, int> num;   int cnt[27][10000];   int g[10000];   int main() {     string s;     cin >> s;     s += (char)( z  + 1);     offset = 1;     while (offset < size(s)) offset *= 2;     memset((f), (0), sizeof(f));     for (int i = offset; i < offset + size(s); ++i) {       f[i] = 1 << (s[i - offset] -  a );     }     for (int i = offset - 1; i >= 1; --i) {       f[i] = f[2 * i] | f[2 * i + 1];     }     for (int i = 0; i < size(s); ++i) {       pos[s[i] -  a ].push_back(i);     }     int q;     cin >> q;     for (int i = 0; i < q; ++i) {       string e;       cin >> e;       int mask = 0;       for (int j = 0; j < e.length(); ++j) {         mask |= 1 << (e[j] -  a );       }       g[i] = mask;       num[mask] = i;     }     for (int i = 0; i < size(s) - 1; ++i) {       for (int b = 0; b < 27; ++b) {         if (s[i] -  a  == b) continue;         while (start[b] < pos[b].size() && pos[b][start[b]] < i) {           ++start[b];         }         if (start[b] < pos[b].size() && pos[b][start[b]] >= i) {           int m = getmask(i, pos[b][start[b]] - 1);           if (i > 0 && (m & (1 << (s[i - 1] -  a ))) != 0) continue;           if (!num.count(m)) continue;           cnt[b][num[m]]++;         }       }     }     for (int i = 0; i < q; ++i) {       int res = 0;       for (int b = 0; b < 27; ++b)         if ((g[i] & (1 << b)) == 0) {           res += cnt[b][num[g[i]]];         }       cout << res << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   string g[51];   int pre[52][52];   int dp[51][51][51][51];   bool chk(int x1, int x2, int y1, int y2) {     int r = pre[x2][y2] - pre[x1][y1 - 1] - pre[x1 - 1][y1] + pre[x1 - 1][y1 - 1];     if (r >= 1) return true;     return false;   }   int fun(int r1, int r2, int c1, int c2) {     if (chk(r1, r2, c1, c2) == false) return 0;     if (dp[r1][r2][c1][c2] != -1) return dp[r1][r2][c1][c2];     int ans = max((r2 - r1 + 1), (c2 - c1 + 1));     for (int i = r1; i < r2; i++)       ans = min(ans, fun(r1, i, c1, c2) + fun(i + 1, r2, c1, c2));     for (int j = c1; j < c2; j++) {       ans = min(ans, fun(r1, r2, c1, j) + fun(r1, r2, j + 1, c2));     }     return dp[r1][r2][c1][c2] = ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     memset(dp, -1, sizeof(dp));     for (int i = 0; i < n; i += 1) cin >> g[i];     pre[0][0] = 1;     for (int i = 0; i < n; i++) {       pre[i][0] = pre[0][i] = 0;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (g[i][j] ==  # ) pre[i + 1][j + 1] = 1;         pre[i + 1][j + 1] += (pre[i][j + 1] + pre[i + 1][j] - pre[i][j]);       }     }     int ans = fun(1, n, 1, n);     cout << ans << endl;     return 0;   }
#include<bits/stdc++.h>   using namespace std;   #define ll long long   #define pb push_back   #define ff first   #define ss second   #define mod 1000000007   #define t5 100005   #define inf 100000000000000000   ll ask(ll t,ll i,ll j , ll x){    cout << ?  << t <<     << i <<     << j <<     << x << endl;    ll temp;    cin >> temp;    return temp;   }   void solve(){    ll n;    cin>> n;    ll pos = 0;    for(ll i=1 ;  i<n ; i+=2){     ll q;     q = ask(2,i,i+1,1);     if(q == 1){      pos = i;      break;     }     else if(q == 2){      q = ask(2,i+1,i,1);      if(q == 1){       pos = i+1;       break;      }     }    }    if(!pos)     pos = n;    vector <ll> v(n+1);    for(ll i=1 ; i<=n ; i++){     if(i==pos){      v[i] = 1;     }     else{      ll q = ask(1,pos,i,n-1);      v[i] = q;     }    }    cout << ! ;    for(ll i=1 ; i<=n ; i++){     cout <<    << v[i];    }    cout << endl;   }   int main(){    ios_base::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);    ll t;    cin >> t;    while(t--){     solve();    }        return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<pair<int, int>> a(n);     vector<int> diff(n), dp(n + 1), take(n + 1);     for (int i = 0; i < n; i++) scanf( %d , &a[i].first), a[i].second = i;     sort(a.begin(), a.end());     if (n < 6) {       cout << a[n - 1].first - a[0].first <<     << 1 << endl;       for (int i = 0; i < n; i++) cout << 1 <<    ;       return 0;     }     for (int i = 0; i < n - 1; i++) diff[i] = a[i + 1].first - a[i].first;     dp[2] = diff[2];     take[2] = 1;     for (int i = 3; i < n - 3; i++) {       if (dp[i - 3] + diff[i] > dp[i - 1]) {         take[i] = 1;         dp[i] = dp[i - 3] + diff[i];       } else {         dp[i] = dp[i - 1];       }     }     vector<int> ans(n);     int cnt = 1;     for (int i = n - 1; i >= 0;) {       if (take[i]) {         ++cnt;         for (int j = 0; j < 3; j++) ans[a[i--].second] = cnt;       } else         ans[a[i--].second] = cnt;     }     cout << a[n - 1].first - a[0].first - dp[n - 4] <<     << cnt << endl;     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[35], b[35], k[35], p[35];   long long n, u, r, ans;   void op1() {     for (int i = 0; i < n; i++) a[i] = a[i] ^ b[i];   }   void op2() {     long long tmp[35];     for (int i = 0; i < n; i++) tmp[i] = a[p[i]] + r;     for (int i = 0; i < n; i++) a[i] = tmp[i];   }   void dfs(int t, int f) {     long long x = 0;     if ((t & 1) == 0) {       for (int i = 0; i < n; i++) x += a[i] * k[i];       ans = max(x, ans);     }     if (t == 0) return;     long long tmp[35];     for (int i = 0; i < n; i++) tmp[i] = a[i];     op2();     dfs(t - 1, 1);     for (int i = 0; i < n; i++) a[i] = tmp[i];     if (f) {       op1();       dfs(t - 1, 0);       for (int i = 0; i < n; i++) a[i] = tmp[i];     }     return;   }   int main() {     cin >> n >> u >> r;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     for (int i = 0; i < n; i++) cin >> k[i];     for (int i = 0; i < n; i++) cin >> p[i], p[i]--;     ans = -100000000000000009;     dfs(u, 1);     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 2, K = 102, P = 102;   int dp[3][K][P], a[N], mn[N][K], pre[N];   int main() {     ios::sync_with_stdio(), cin.tie(0), cout.tie(0);     int n, k, p;     cin >> n >> k >> p;     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i] %= p;     }     if (10000 >= n) {       for (int i = 0; i <= 100; i++)         for (int j = 0; j <= 100; j++) dp[0][i][j] = 1e8;       for (int i = 0; i <= 10000; i++)         for (int j = 0; j <= 100; j++) mn[i][j] = 1e8;       dp[0][0][0] = 0;       mn[0][0] = 0;       for (int i = 1; i <= n; i++) {         int nw = (i & 1);         int pas = (nw ^ 1);         for (int ii = 0; ii <= 100; ii++)           for (int j = 0; j <= 100; j++) dp[nw][ii][j] = 1e8;         for (int j = 1; j <= k; j++) {           for (int las = 0; las < p; las++) {             if (las == a[i - 1]) {               dp[nw][j][las] = mn[i - 1][j - 1] + a[i - 1];             }             dp[nw][j][las] =                 min(dp[nw][j][las], dp[pas][j][((las - a[i - 1] + p) % p)] -                                         ((las - a[i - 1] + p) % p) + las);             mn[i][j] = min(mn[i][j], dp[nw][j][las]);           }         }       }       int ans = 1e8;       for (int i = 0; i < p; i++) {         ans = min(ans, dp[n & 1][k][i]);       }       cout << ans;     } else {       for (int i = 1; i <= n; i++) {         pre[i] = pre[i - 1] + a[i - 1];         pre[i] %= p;       }       vector<int> lis;       lis.clear();       for (int i = 1; i < n; i++) {         auto it = upper_bound(lis.begin(), lis.end(), pre[i]);         if (it == lis.end()) {           lis.emplace_back(pre[i]);         } else {           lis[it - lis.begin()] = pre[i];         }       }       auto it = upper_bound(lis.begin(), lis.end(), pre[n]);       if (it - lis.begin() + 1 >= k)         cout << pre[n];       else         cout << pre[n] + p;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   template <typename T>   ostream& operator<<(ostream& out, vector<T> v) {     out <<  { ;     for (size_t i = 0; i < v.size(); ++i) out << (i == 0 ?    :  ,  ) << v[i];     return out <<  } ;   }   template <typename Arg1>   void myPrint(const char* name, Arg1&& arg1) {     std::cout << name <<  =  << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void myPrint(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     std::cout.write(names, comma - names) <<  =  << arg1;     myPrint(comma, args...);   }   void run();   int main() {     if (strlen(  ) > 0) {       freopen(                         .in ,            r , stdin);       freopen(                         .out ,            w , stdout);     }     run();     return 0;   }   long long n, q;   long long add[2];   void run() {     scanf( %d%d , &n, &q);     while (q--) {       int t, x;       scanf( %d , &t);       if (t == 1) {         scanf( %d , &x);         if (x < 0) x += n;         add[0] += x;         add[1] += x;       } else {         if (add[0] % 2) {           --add[0];           ++add[1];         } else {           ++add[0];           --add[1];         }       }     }     vector<int> a(n);     for (int i = 0; i < n; ++i) a[((i + add[i % 2]) % n + n) % n] = i;     for (int x : a) printf( %d  , x + 1);     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   int ar[1000009];   int main() {     long long a, s, d, f, g, h, j, k, l;     cin >> a;     k = 0;     for (s = 1; s <= a; s++) {       scanf( %d , &ar[s]);       if (ar[s]) k++;     }     d = 0;     l = 0;     for (s = 1; s <= a; s++) {       if (ar[s] == 1) {         d = d + (a - k - l);       } else         l++;     }     f = 0;     for (s = a; s >= 1; s--) {       if (ar[s] == 0)         f = f + k;       else         k--;     }     cout << min(d, f) << endl;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, count, area;     cin >> a >> b;     area = a * b;     if (area < 2)       cout <<  0  << endl;     else {       while (area >= 2) {         count++;         area -= 2;       }       cout << count << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, m;   vector<long long int> a[200005];   long long int rankof[200005];   long long int parentof[200005];   long long int maxof[200005];   void initialize() {     for (long long int i = 0; i <= 200005; i++) {       rankof[i] = 1;       parentof[i] = i;       maxof[i] = i;     }   }   long long int root(long long int x) {     if (x == parentof[x]) {       return x;     }     parentof[x] = root(parentof[x]);     return parentof[x];   }   void combine(long long int x, long long int y) {     x = root(x);     y = root(y);     long long int maxx = max(maxof[x], maxof[y]);     if (x != y) {       if (rankof[x] >= rankof[y]) {         parentof[y] = x;         rankof[x] += rankof[y];         maxof[x] = maxx;       } else {         parentof[x] = y;         rankof[y] += rankof[x];         maxof[y] = maxx;       }     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int i, j;     cin >> n >> m;     initialize();     for (i = 0; i < m; i++) {       long long int u, v;       cin >> u >> v;       combine(u, v);     }     long long int curmax, cnt = 0;     for (i = 1; i <= n;) {       curmax = maxof[root(i)];       j = i + 1;       while (j <= curmax) {         if (root(j) != root(i)) {           combine(i, j);           cnt++;         }         curmax = maxof[root(i)];         j++;       }       i = j;     }     cout << cnt;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   int L[N], R[N], sp[N], levsp[30], lev[N];   long long val[N], a[N];   void lazyUpdate(int node) {     if (!L[node]) return;     if (sp[node] ^ levsp[lev[node]]) {       swap(L[node], R[node]);       sp[node] ^= 1;     }   }   long long build(int node, int l, int r, int lv) {     if (l == r) return val[node] = a[l];     int mid = l + r >> 1;     lev[node] = lv;     L[node] = node << 1, R[node] = node << 1 | 1;     val[node] =         build(L[node], l, mid, lv - 1) + build(R[node], mid + 1, r, lv - 1);     return val[node];   }   long long update(int node, int l, int r, int pos, int k) {     lazyUpdate(node);     if (r < pos || l > pos) return val[node];     if (l == r) return val[node] = k;     int mid = l + r >> 1;     return val[node] = update(L[node], l, mid, pos, k) +                        update(R[node], mid + 1, r, pos, k);   }   long long query(int node, int l, int r, int pos) {     lazyUpdate(node);     if (l > pos) return 0;     if (r <= pos) return val[node];     int mid = l + r >> 1;     return query(L[node], l, mid, pos) + query(R[node], mid + 1, r, pos);   }   int main() {     int n, q;     scanf( %d%d , &n, &q);     int nn = 1 << n;     for (int i = 1; i <= nn; i++) scanf( %lld , &a[i]);     build(1, 1, nn, n);     while (q--) {       int t, x, k;       scanf( %d , &t);       if (t == 1) {         scanf( %d%d , &x, &k);         update(1, 1, nn, x, k);       } else if (t == 2) {         scanf( %d , &k);         for (int i = 0; i <= k; i++) levsp[i] ^= 1;       } else if (t == 3) {         scanf( %d , &k);         levsp[k + 1] ^= 1;       } else {         int l, r;         scanf( %d%d , &l, &r);         printf( %lld n , query(1, 1, nn, r) - query(1, 1, nn, l - 1));       }     }     return 0;   }