malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   set<int> ss;   map<int, int> mm;   int arr[2 * 100003], pr[2 * 100003], nxt[2 * 100003];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, k;     cin >> n >> k;     for (int i = 0; i < int(n); i++) {       cin >> arr[i + 1];       ss.insert(arr[i + 1]);       mm[arr[i + 1]] = i + 1;       pr[i + 1] = i;       nxt[i + 1] = i + 2;     }     int ans[n + 1];     for (int i = 0; i < int(n); i++) {       if (ss.empty()) break;       int pos = mm[(*ss.rbegin())];       int tch = 1 + (i % 2);       ans[pos] = tch;       ss.erase(arr[pos]);       int p_f = pos, p_b = pos;       int j = k;       while (nxt[p_f] != n + 1 and j--) {         p_f = nxt[p_f];         ss.erase(arr[p_f]);         ans[p_f] = tch;       }       j = k;       while (pr[p_b] != 0 and j--) {         p_b = pr[p_b];         ans[p_b] = tch;         ss.erase(arr[p_b]);       }       pr[nxt[p_f]] = pr[p_b];       nxt[pr[p_b]] = nxt[p_f];     }     for (int i = 0; i < int(n); i++) cout << ans[i + 1];     cout <<   n ;     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int v1, v2, t, d, i = 2;     scanf( %d%d%d%d , &v1, &v2, &t, &d);     int sum = v1 + v2;     while (i != t) {       i++;       if (v1 < v2) {         v1 += d;         sum += v1;       } else {         v2 += d;         sum += v2;       }     }     printf( %d , sum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using pii = pair<int, int>;   using vi = vector<int>;   using vvi = vector<vi>;   const int INF = 2e9 + 5;   int main() {     cin.tie(0), cin.sync_with_stdio(0), cout.tie(0), cout.sync_with_stdio(0);     int n;     cin >> n;     vi l(n), r(n);     for (int i = 0; i < n; i++) {       cin >> l[i] >> r[i];     }     sort(l.begin(), l.end());     sort(r.begin(), r.end());     ll ans = n;     for (int i = 0; i < n; i++) ans += max(l[i], r[i]);     cout << ans;     return cout <<   n , 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const long long oo = INT_MAX;   const long long MOD = 1e9 + 7;   const long long sz = 1e5 + 5;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long tc = 1;     while (tc--) {       long long n;       cin >> n;       vector<long long> tree[n + 1];       for (long long i = 2; i < n + 1; ++i) {         long long p;         cin >> p;         tree[i].push_back(p);         tree[p].push_back(i);       }       vector<long long> nodeCnt(n + 1, 0);       vector<double> startTime(n + 1, 0.0);       startTime[1] = 1.0;       function<long long(long long, long long)> dfs1 = [&](long long node,                                                            long long parent) {         long long cnt = 1;         for (auto child : tree[node]) {           if (child != parent) {             cnt += dfs1(child, node);           }         }         nodeCnt[node] = cnt;         return cnt;       };       function<void(long long, long long)> dfs2 = [&](long long node,                                                       long long parent) {         long long ncnt = nodeCnt[node] - 1, cnt = 0;         for (auto child : tree[node]) {           if (child != parent) {             startTime[child] =                 ((ncnt - nodeCnt[child]) * 1.0) / 2 + (1.0 + startTime[node]);             dfs2(child, node);           }         }       };       dfs1(1, 0);       dfs2(1, 0);       for (long long i = 1; i < n + 1; ++i)         cout << fixed << setprecision(1) << startTime[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int k;     cin >> k;     map<char, int> dict;     for (int i = 0; i < 27; i++) dict[i +  a ] = 0;     for (int i = 0; i < s.length(); i++) dict[s[i]]++;     map<char, int>::iterator it;     vector<pair<int, char> > letras;     pair<int, char> aux;     int distinto;     for (it = dict.begin(); it != dict.end(); ++it) {       aux = make_pair((*it).second, (*it).first);       if (aux.first != 0) letras.push_back(aux);     }     sort((letras).begin(), (letras).end());     distinto = letras.size();     int l = 0;     int j = 0;     while (true) {       j += letras[l].first;       if (j > k) break;       l++;       if (j == k) break;       if (l == distinto) break;     }     if (l == distinto) {       cout << 0 << endl;       cout << endl;       return 0;     }     bool ltras[28];     memset(ltras, 0, sizeof(ltras));     for (int i = l; i < letras.size(); i++) {       ltras[letras[i].second -  a ] = 1;     }     string res =   ;     for (int i = 0; i < s.length(); i++)       if (ltras[s[i] -  a ]) res += s[i];     cout << distinto - l << endl;     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, p;   int dp[105][55];   int modd(int x) {     if (x < 0)       return x + p;     else if (x >= p)       return x - p;     return x;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     cin >> n >> k >> p;     memset(dp, 128, sizeof dp);     dp[0][0] = 0;     int z = 0;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       z = (z + x) % p;       vector<int> vz(55, -2e9);       for (int l = 0; l < k; l++) {         for (int j = 0; j < p; j++) {           vz[l + 1] = max(vz[l + 1], dp[j][l] + modd(z - j + p));         }       }       for (int i = 0; i < 55; i++) dp[z][i] = max(dp[z][i], vz[i]);     }     cout << dp[z][k] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   void fileio() {}   vector<vector<long long int>> g;   vector<long long int> bit;   long long int n;   void add(long long int i, long long int x) {     while (i <= n) {       bit[i] += x;       i += (i & (-i));     }   }   long long int query(long long int i) {     long long int sum = 0;     while (i > 0) {       sum += bit[i];       i -= (i & (-i));     }     return sum;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     fileio();     cin >> n;     bit = vector<long long int>(n + 1, 0);     vector<long long int> p(n, 0), candi(n + 1, 0), contri(n + 1, 0);     set<long long int> s;     for (long long int i = 0; i < n; i++) {       cin >> p[i];       long long int more = query(n) - query(p[i]);       add(p[i], 1);       if (more == 1) {         long long int x = (*s.rbegin());         candi[x]++;       }       if (more == 0) {         contri[p[i]]++;       }       s.insert(p[i]);     }     long long int res = 1;     for (long long int i = 1; i <= n; i++)       if (candi[i] - contri[i] > candi[res] - contri[res]) res = i;     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   using min_pq = priority_queue<T, vector<T>, greater<T>>;   const int MAXN = 1e5 + 10, MAXQ = 3e5 + 10, MAXL = 18, ALP = 26, MOD = 1e9 + 7,             MAXK = 17, MAXA = 10, MAXB = 24, MAXBB = (1 << MAXB);   const string no =  NO n , yes =  YES n ;   const int hA[4] = {1, 0, -1, 0}, kA[4] = {0, 1, 0, -1};   const int INF = 1e9 + 10;   int n, par[MAXN], md[MAXN], st[MAXN], tt = 0;   vector<int> adj[MAXN];   int dfs1(int c = 0) {     md[c] = 1;     for (auto nxt : adj[c]) md[c] = max(md[c], dfs1(nxt) + 1);     return md[c];   }   void dfs2(int c = 0) {     sort(adj[c].begin(), adj[c].end(),          [&](int i, int j) { return md[i] < md[j]; });     st[tt++] = c;     for (auto nxt : adj[c]) dfs2(nxt);   }   void solve() {     cin >> n;     for (int i = 1; i < n; i++) {       cin >> par[i], adj[par[i]].push_back(i);     }     dfs1(), dfs2();     vector<int> ans;     ans.reserve(n);     for (int i = 1; i < n; i++) {       for (int a = st[i], b = st[i - 1]; b != par[a]; b = par[b])         ans.push_back(a);     }     for (int i = 0; i < n; i++) cout << st[i] <<    ;     cout <<   n ;     cout << (int)ans.size() <<   n ;     for (int c : ans) cout << c <<    ;     cout <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t_c = 1;     while (t_c--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     map<long long, long long> rt, lf;     long long a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];       rt[a[i]]++;     }     long long ans = 0;     for (long long i = 0; i < n; i++) {       if (a[i] % k == 0) {         long long l = a[i] / k;         rt[a[i]]--;         long long r = a[i] * k;         ans += rt[r] * lf[l];       }       lf[a[i]]++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long MOD2 = 998244353;   const float pi = 3.141592653;   long long power(long long a, long long b) {     if (b == 0) return 1;     long long p = power(a, b / 2);     if (b & 1)       return p * p * a;     else       return p * p;   }   void solve() {     long long n, k;     cin >> n >> k;     vector<long long> a, b, c;     for (long long i = 0; i < n; i++) {       long long o, t, f;       cin >> o >> t >> f;       if (t == 1 && f == 1)         c.push_back(o);       else if (t == 1)         a.push_back(o);       else if (f == 1)         b.push_back(o);     }     if (a.size() + c.size() < k || b.size() + c.size() < k) {       cout << -1;       return;     }     sort(a.begin(), a.end());     sort(b.begin(), b.end());     sort(c.begin(), c.end());     long long ans = 0, count = 0, index1 = 0, index2 = 0;     while (1) {       if (index2 == min(a.size(), b.size()) || index1 == c.size()) break;       if (a[index2] + b[index2] <= c[index1]) {         ans += a[index2] + b[index2];         index2++;       } else {         ans += c[index1];         index1++;       }       count++;       if (count == k) break;     }     if (index1 < c.size()) {       while (count < k) {         ans += c[index1];         index1++;         count++;       }     }     if (index2 < min(a.size(), b.size())) {       while (count < k) {         count++;         ans += (a[index2] + b[index2]);         index2++;       }     }     cout << ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, V, i, x, y, z, tot, e[505], fir[505], ne[505 * 2], la[505 * 2],       va[505 * 2];   double v, o, a[505][505], b[505], c[505];   void ins(int x, int y, int z) {     la[++tot] = y;     ne[tot] = fir[x];     fir[x] = tot;     va[tot] = z;   }   void dfs(int A, int x, int fa, long long z) {     if (z <= V) a[x][A] = 1;     for (int i = fir[x]; i; i = ne[i])       if (la[i] != fa) dfs(A, la[i], x, z + va[i]);   }   void pivot(int l, int e) {     int i, j;     for (a[l][e] = 1 / a[l][e], b[l] *= a[l][e], i = 1; i <= n; i++)       if (i != e) a[l][i] *= a[l][e];     for (i = 1; i <= m; i++)       if (i != l && fabs(a[i][e]) > 1e-7) {         for (b[i] -= a[i][e] * b[l], j = 1; j <= n; j++)           if (j != e) a[i][j] -= a[i][e] * a[l][j];         a[i][e] *= -a[l][e];       }     for (v += c[e] * b[l], i = 1; i <= n; i++)       if (i != e) c[i] -= c[e] * a[l][i];     c[e] *= -a[l][e];   }   double simplex() {     for (int i, j, e, l; 1;) {       for (i = 1; i <= n; i++)         if (c[i] > 1e-7) break;       if ((e = i) == n + 1) return v;       double tmp = 1e99;       for (i = 1; i <= m; i++)         if (a[i][e] > 1e-7 && tmp > b[i] / a[i][e]) tmp = b[i] / a[i][e], l = i;       if (tmp == 1e99) break;       pivot(l, e);     }     return 1e99;   }   int main() {     for (scanf( %d%d , &n, &V), i = 1; i <= n; i++)       scanf( %d , &e[i]), b[i] = !e[i], a[i][n + 1] = 1, a[i][n + 2] = -1,                           c[n + 1] += e[i], c[n + 2] -= e[i], c[i] = 1;     for (i = 1; i < n; i++)       scanf( %d%d%d , &x, &y, &z), ins(x, y, z), ins(y, x, z);     for (i = 1; i <= n; i++) dfs(i, i, 0, 0);     m = n;     n += 2;     o = simplex();     if (o == 1e99)       puts( -1 );     else       printf( %.0lf , o);   }
#include <bits/stdc++.h>   using namespace std;   int M[17], R[17], n, sum;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> M[i];     for (int i = 1; i <= n; i++) cin >> R[i];     for (int i = 1; i <= 720719; i++)       for (int j = 1; j <= n; j++) {         if (i % M[j] == R[j]) {           sum++;           break;         }       }     double ans = 1.0 * sum / 720720;     printf( %.6lf , ans);   }
#include <bits/stdc++.h>   using namespace std;   int op[1000005];   bool value[1000005];   bool change[1000005];   long req[1000005][2];   bool calc(long i) {     if (i <= 0) return false;     value[i] = false;     if (op[i] == 4) {       value[i] = (req[i][0] == 1);     }     if (op[i] == 3) {       value[i] = !(calc(req[i][0]));     }     if (op[i] == 2) {       value[i] = (calc(req[i][0]) ^ calc(req[i][1]));     }     if (op[i] == 1) {       value[i] = (calc(req[i][0]) | calc(req[i][1]));     }     if (op[i] == 0) {       value[i] = (calc(req[i][0]) & calc(req[i][1]));     }     return value[i];   }   void backTrace(long i, bool vt, bool vf) {     if (op[i] == 4) {       if (value[i])         change[i] = vf;       else         change[i] = vt;     }     if (op[i] == 3) {       backTrace(req[i][0], vf, vt);     }     if (op[i] == 2) {       if (value[req[i][1]]) {         backTrace(req[i][0], vf, vt);       } else {         backTrace(req[i][0], vt, vf);       }       if (value[req[i][0]]) {         backTrace(req[i][1], vf, vt);       } else {         backTrace(req[i][1], vt, vf);       }     }     if (op[i] == 1) {       if (value[req[i][1]]) {         backTrace(req[i][0], vt, vt);       } else {         backTrace(req[i][0], vt, vf);       }       if (value[req[i][0]]) {         backTrace(req[i][1], vt, vt);       } else {         backTrace(req[i][1], vt, vf);       }     }     if (op[i] == 0) {       if (value[req[i][1]]) {         backTrace(req[i][0], vt, vf);       } else {         backTrace(req[i][0], vf, vf);       }       if (value[req[i][0]]) {         backTrace(req[i][1], vt, vf);       } else {         backTrace(req[i][1], vf, vf);       }     }   }   int main() {     long n;     cin >> n;     string s;     for (long i = 1; i <= n; ++i) {       cin >> s;       if (s ==  AND ) {         op[i] = 0;         cin >> req[i][0] >> req[i][1];       } else if (s ==  OR ) {         op[i] = 1;         cin >> req[i][0] >> req[i][1];       } else if (s ==  XOR ) {         op[i] = 2;         cin >> req[i][0] >> req[i][1];       } else if (s ==  NOT ) {         op[i] = 3;         cin >> req[i][0];       } else {         op[i] = 4;         cin >> req[i][0];       }     }     calc(1);     backTrace(1, true, false);     for (long i = 1; i <= n; ++i) {       if (op[i] == 4) {         if (change[i])           cout << 1;         else           cout << 0;       }     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, a[N], lm[N], rm[N], q[N];   vector<int> tree[35];   long long ans;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       for (int j = 0; (1 << j) <= a[i]; j++)         if (a[i] & (1 << j)) tree[j].push_back(i);     }     int tail = 0;     for (int i = 1; i <= n; i++) {       while (tail && a[q[tail - 1]] < a[i]) tail--;       lm[i] = tail ? q[tail - 1] + 1 : 1;       q[tail++] = i;     }     tail = 0;     for (int i = n; i; i--) {       while (tail && a[q[tail - 1]] <= a[i]) tail--;       rm[i] = tail ? q[tail - 1] - 1 : n;       q[tail++] = i;     }     for (int i = 1; i <= n; i++) {       if (lm[i] == rm[i]) continue;       int tl = lm[i] - 1, tr = rm[i] + 1;       for (int j = 0; (1 << j) <= a[i]; j++)         if (!((1 << j) & a[i])) {           if (tree[j].size() == 0) continue;           auto it = lower_bound(tree[j].begin(), tree[j].end(), i);           if (it != tree[j].begin()) {             it--;             tl = max(tl, *it);           }           it = upper_bound(tree[j].begin(), tree[j].end(), i);           if (it != tree[j].end()) tr = min(tr, *it);         }       ans +=           1ll * (i - lm[i] + 1) * (rm[i] - i + 1ll) - 1ll * (i - tl) * (tr - i);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     char c;     while (~scanf( %d , &n)) {       c =  a ;       for (i = 1; i <= n; i++) {         printf( %c , c);         c++;         if (c ==  e ) c =  a ;       }       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   bool isPrime(long long int n) {     for (long long int i = 2; i * i <= n; i++) {       if (n % i == 0) {         return false;       }     }     return true;   }   bool isPowerOfTwo(long long int x) { return (x && (!(x & (x - 1)))); }   long long int countDigit(long long int num) { return (floor(log10(num)) + 1); }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int test_case = 1;     while (test_case--) {       long long int n;       cin >> n;       long long int arr[n];       for (long long int i = 0; i < n; i++) {         cin >> arr[i];       }       long long int maxx = 0;       vector<long long int> ans;       for (long long int i = n - 1; i >= 0; i--) {         if (arr[i] <= maxx) {           ans.push_back(maxx - arr[i] + 1);         } else {           ans.push_back(0);         }         maxx = max(arr[i], maxx);       }       reverse(ans.begin(), ans.end());       for (auto it : ans) {         cout << it <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void shift(vector<int> &ans) {     for (int i = 0; i < ans.size() - 1; i++) {       ans[i] = ans[i + 1];     }   }   bool check(vector<int> ans, int c) {     for (int i = 0; i < ans.size(); i++) {       if (c == ans[i]) return true;     }     return false;   }   int main() {     int n, k;     cin >> n >> k;     vector<int> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     vector<int> ans;     for (int i = 0; i < n; i++) {       if (ans.size() < k && (!check(ans, v[i])))         ans.push_back(v[i]);       else if (!check(ans, v[i])) {         shift(ans);         ans[ans.size() - 1] = v[i];       }     }     cout << ans.size() << endl;     for (int i = ans.size() - 1; i >= 0; i--) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[3];   long long kq;   void nhap() { cin >> a[0] >> a[1] >> a[2]; }   void cbi() { sort(a, a + 3); }   void xuli() {     if (a[0] == a[1] && a[1] == a[2]) {       cout << a[0];       exit(0);     }     if (a[0] + a[1] < a[2] / 2)       kq = 1ll * a[0] + a[1];     else       kq = 1ll * (a[0] + a[1] + a[2]) / 3;   }   void ghikq() { cout << kq; }   int main() {     nhap();     cbi();     xuli();     ghikq();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int INF = 0x7ffffff;   const int magic = 348;   string s1, s2;   string s;   int n;   int nxt1[200], nxt2[200];   int main() {     cin >> s1 >> s2;     cin >> n;     n %= 4;     nxt1[94] = 62;     nxt1[62] = 118;     nxt1[118] = 60;     nxt1[60] = 94;     nxt2[94] = 60;     nxt2[60] = 118;     nxt2[118] = 62;     nxt2[62] = 94;     bool f1 = false, f2 = false;     s = s1;     for (int i = 1; i <= n; i++) s[0] = nxt1[s[0]];     if (s == s2) f1 = true;     s = s1;     for (int i = 1; i <= n; i++) s[0] = nxt2[s[0]];     if (s == s2) f2 = true;     if (f1 && f2) {       cout <<  undefined  << endl;     } else {       if (f1)         cout <<  cw  << endl;       else         cout <<  ccw  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 300000;   const int MAX_E2 = 1 << 20;   struct Elm {     int l, r, v;     Elm() {}     Elm(int _l, int _r, int _v) : l(_l), r(_r), v(_v) {}     Elm(int _l) : l(_l), r(_l), v(1) {}     Elm operator+(const Elm &e) const {       if (v == 0) return e;       if (e.v == 0) return *this;       Elm a;       a.l = l, a.r = e.r;       a.v = v + e.v - ((r < e.l) ? 1 : 0);       return a;     }   };   template <typename T, const int MAX_E2>   struct SegTreeSum {     int n, e2;     T nodes[MAX_E2], z;     SegTreeSum() {}     void init(int n, T _z) {       z = _z;       for (e2 = 1; e2 < n; e2 <<= 1)         ;       fill(nodes, nodes + MAX_E2, z);     }     T &get(int i) { return nodes[e2 - 1 + i]; }     void setall() {       for (int j = e2 - 2; j >= 0; j--)         nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2];     }     void set(int i, T v) {       int j = e2 - 1 + i;       nodes[j] = v;       while (j > 0) {         j = (j - 1) / 2;         nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2];       }     }     T sum_range(int r0, int r1, int k, int i0, int i1) {       if (r1 <= i0 || i1 <= r0) return z;       if (r0 <= i0 && i1 <= r1) return nodes[k];       int im = (i0 + i1) / 2;       T v0 = sum_range(r0, r1, k * 2 + 1, i0, im);       T v1 = sum_range(r0, r1, k * 2 + 2, im, i1);       return v0 + v1;     }     T sum_range(int r0, int r1) { return sum_range(r0, r1, 0, 0, e2); }   };   int as[MAX_N];   SegTreeSum<Elm, MAX_E2> st;   int main() {     int n;     scanf( %d , &n);     st.init(n, Elm(0, 0, 0));     for (int i = 0; i < n; i++) {       scanf( %d , as + i);       as[i]--;       st.get(as[i]) = Elm(i, i, 1);     }     st.setall();     int q;     scanf( %d , &q);     while (q--) {       int p, x, y;       scanf( %d%d%d , &p, &x, &y);       if (p == 1) {         x--;         Elm e = st.sum_range(x, y);         printf( %d n , e.v);       } else {         x--, y--;         int ax = as[x], ay = as[y];         swap(as[x], as[y]);         st.set(ax, Elm(y));         st.set(ay, Elm(x));       }     }     return 0;   }