malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 7;   long long a[maxn], b[maxn];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i] >> b[i];       a[i] ^= b[i], b[i] ^= b[i - 1];     }     vector<long long> linbs;     for (int i = 1; i <= n; i++) {       long long temp = a[i];       for (auto &e : linbs) temp = min(temp, temp ^ e);       if (temp) {         for (auto &e : linbs) e = min(e, e ^ temp);         linbs.push_back(temp);       }     }     for (auto &e : linbs) b[n] = min(b[n], b[n] ^ e);     if (b[n])       cout << 1 <<  /  << 1 << endl;     else {       int sz = linbs.size();       long long t1 = 1ll << sz, t2 = t1 - 1;       cout << t2 <<  /  << t1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int mod = 1000000007;   void __print(long long int x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename Th, typename V>   void __print(const pair<Th, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename Th>   void __print(const Th &x) {     long long int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename Th, typename... V>   void _print(Th t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   void binary_rock() {     long long int v, c, n, m;     cin >> v >> c >> n >> m;     if (v + c < n + m) {       cout <<  No  << endl;       return;     }     long long int mini = min(v, c);     if (mini >= m) {       cout <<  Yes  << endl;       return;     }     if (v >= c) {       long long int req = (v - c);       if (n < req) {         cout <<  No  << endl;         return;       }       n -= req;       v -= req;       if (n >= m) {         cout <<  Yes  << endl;         return;       }       m -= n;       v -= n;       c -= n;       n -= n;       if (m > v) {         cout <<  No  << endl;         return;       } else {         cout <<  Yes  << endl;         return;       }       return;     } else {       long long int req = (c - v);       if (n < req) {         cout <<  No  << endl;       } else {         n -= req;         c -= req;         if (n >= m) {           cout <<  Yes  << endl;           return;         }         m -= n;         v -= n;         c -= n;         n -= n;         if (m > v) {           cout <<  No  << endl;           return;         } else {           cout <<  Yes  << endl;           return;         }         cout <<  Yes  << endl;       }       return;     }   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     clock_t t1 = clock();     long long int t = 1;     cin >> t;     while (t--) {       binary_rock();     }     clock_t t2 = clock();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 305, Q = (int)2e6 + 50;   struct Qry {     int x, y, c;     void read() {       cin >> x >> y >> c;       x--, y--;     }   } qry[Q];   int n, m, q;   int mp[N][N];   int f[N * N];   int dx[] = {0, 0, -1, 1}, dy[] = {1, -1, 0, 0};   int ch[Q], off[Q];   int ans[Q];   int gid(int i, int j) { return i * m + j; }   int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }   bool unite(int x, int y) {     x = find(x);     y = find(y);     if (x == y) return false;     f[x] = y;     return true;   }   int build(int val, int ig) {     for (int k = 0; k < n * m; k++) {       f[k] = k;     }     for (int ki = 0; ki < n; ki++) {       for (int kj = 0; kj < m; kj++) {         if (ig != -1 && (!((mp[ki][kj] == val) ^ ig))) continue;         if (ki + 1 < n && mp[ki + 1][kj] == mp[ki][kj])           unite(gid(ki + 1, kj), gid(ki, kj));         if (kj + 1 < m && mp[ki][kj + 1] == mp[ki][kj])           unite(gid(ki, kj + 1), gid(ki, kj));       }     }     int ccnt = 0;     for (int k = 0; k < n * m; k++) ccnt += (f[k] == k);     return ccnt;   }   bool in_bound(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m >> q;     for (int i = 0; i < q; i++) qry[i].read();     int r = 0;     for (int i = 0; i < q; i = r) {       while (r < q && qry[r].c == qry[i].c) r++;       build(qry[i].c, 0);       int cur = 0;       for (int j = i; j < r; j++) {         int x = qry[j].x, y = qry[j].y;         ch[j] = mp[x][y];         if (mp[x][y] != qry[j].c) cur++;         mp[x][y] = qry[j].c;         for (int d = 0; d < 4; d++) {           int nx = x + dx[d], ny = y + dy[d];           if (in_bound(nx, ny) && mp[x][y] == mp[nx][ny]) {             if (unite(gid(x, y), gid(nx, ny))) cur--;           }         }         off[j] += cur;       }       cur = 0;       build(qry[i].c, 1);       for (int j = r - 1; j >= i; j--) {         off[j] += cur;         int x = qry[j].x, y = qry[j].y;         if (mp[x][y] != ch[j]) {           cur++;           mp[x][y] = ch[j];           for (int d = 0; d < 4; d++) {             int nx = x + dx[d], ny = y + dy[d];             if (in_bound(nx, ny) && mp[x][y] == mp[nx][ny]) {               if (unite(gid(x, y), gid(nx, ny))) cur--;             }           }         }       }       int ccnt = build(qry[i].c, -1);       for (int j = i; j < r; j++) {         ans[j] = ccnt - cur + off[j];       }       for (int j = i; j < r; j++) {         int x = qry[j].x, y = qry[j].y;         mp[x][y] = qry[j].c;       }     }     for (int i = 0; i < q; i++) cout << ans[i] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, x[105], mem[101][201][51][3], ans;   string s;   int solve(int idx, int pos, int rem, int dir) {     int &ret = mem[idx][100 + pos][rem][dir + 1];     if (rem == 0) {       int cur_dir = dir, sum = 0;       for (int i = idx; i < s.size(); i++)         if (x[i])           sum += cur_dir;         else           cur_dir *= -1;       return abs(pos + sum);     }     if (idx == s.size()) return -1e8;     if (ret != -1) return ret;     int next_dir = (x[idx]) ? dir : -dir;     int c1 = solve(idx + 1, pos + x[idx] * dir, rem, next_dir);     int new_dir = (x[idx]) ? -dir : dir;     int new_pos = (x[idx]) ? pos : pos + dir;     int c2 = -1e8;     if (rem >= 2) c2 = solve(idx, pos, rem - 2, dir);     int c3 = -1e8;     if (rem >= 1) c3 = solve(idx + 1, new_pos, rem - 1, new_dir);     ans = max(ans, max(max(c1, c2), c3));     return ret = ans;   }   int main() {     cin >> s >> n;     memset(mem, -1, sizeof mem);     for (int i = 0; i < s.size(); i++) x[i] = (s[i] ==  F );     cout << max(solve(0, 0, n, -1), solve(0, 0, n, 1));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, p, x;   long long Pow(long long x, long long y, long long mod) {     if (!y) return 1;     if (y == 1) return x % mod;     long long t = Pow(x, y >> 1, mod), ans = t * t % mod;     if (y & 1) ans = ans * x % mod;     return ans;   }   int main() {     while (scanf( %lld %lld %lld %lld , &a, &b, &p, &x) != EOF) {       long long P = p * (p - 1), ans = 0;       for (long long i = 1; i < p; i++) {         long long r = b * Pow(Pow(a, i, p), p - 2, p) % p, c;         if (i >= r)           c = (i + (i - r) * (p - 1)) % P;         else           c = (i + (i + p - r) * (p - 1)) % P;         if (!c) c = P;         ans += ((x / P) + ((x % P >= c) ? 1 : 0));       }       printf( %lld n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int i, j;     if (k == 1 && n == 1) {       cout <<  a ;       return 0;     }     if (k > n || (k == 1)) {       cout << -1;       return 0;     }     i = 1;     while (n - i >= k - 2) {       cout << char( a  + !(i % 2));       ++i;     }     for (i = 2; i < k; i++) cout << char( a  + i);     return 0;   }
#include<bits/stdc++.h>   #include<vector>   #include<map>   #include<queue>   #define LL long long   #define INF INT64_MAX   #define MOD 1000000007   #define stree SegTree[root]   #define lson SegTree[root << 1]   #define rson SegTree[root << 1 | 1]   using namespace std;   const int N = 100005;   LL a[N];   int main()   {       int t, n;       cin>>t;       LL Min = INF;       int tt = 0;       while(t--)       {           tt++;           cin>>n;           for(int i = 1;i <= n;i++)           {               cin>>a[i];           }           LL ans = INF, tem = 0, m1 = INT_MAX, m2 = INT_MAX;           for(int i = 1;i <= n;i++)           {               if(i&1)               {                   m1 = min(m1, a[i]);                   ans = min(ans, tem + m1*(n-i/2) + m2*(n-i/2));                   tem += a[i];                   //printf( 1ans = %lld tem = %lld n , ans, tem);               }               else               {                   m2 = min(m2, a[i]);                   ans = min(ans, tem + m2*(n-(i-1)/2) + m1*(n-i/2));                   tem += a[i];                   //printf( 2ans = %lld tem = %lld n , ans, tem);               }           }           printf( %lld n , ans);       }       return 0;   }
#include <bits/stdc++.h>   #include <time.h>   using namespace std;      #define ll long long   #define ld long double   #define precision(x,d) cout<<fixed<<setprecision(d)<<x   #define all(x) x.begin(),x.end()   #define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));   #define MOD 1000000007   #define INF LONG_LONG_MAX   #define NINF LONG_LONG_MIN   #define endl   n    #define yes cout<< YES <<endl   #define no cout<< NO <<endl   #define db4(x,y,z,k) cout<<#x<<  :  <<x<<  t <<#y<<  :  <<y<<  t <<#z<<  :  <<z<<  t <<#k<<  :  <<k<<endl;      int main()   {       IOS;       ll t,n,m,k,u,v,x,y;       t=1;       cin >> t;       while(t--)       {           cin >> n;           vector<ll> a(n);           for(int i=0;i<n;i++)               cin >> a[i];           sort(all(a));           ll ans = 0;           for(int i=1;i<n;i++)           {               m = i;               ans -= m*a[i];               k = (n-i-1);               ans += k*a[i];           }           ans += a[n-1];           cout << ans << endl;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int c[301];   vector<int> a[301];   vector<int> lt[301];   int id[301];   int dem = 0;   int d[301];   void nhap() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &c[i]);       id[c[i]] = i;     }     for (int i = 1; i <= n; i++) {       string s;       cin >> s;       for (int j = 0; j < s.length(); j++) {         if (s[j] ==  1 ) {           int u = c[i];           int v = c[j + 1];           a[u].push_back(v);           a[v].push_back(u);         }       }     }   }   void bfs(int s) {     queue<int> q;     q.push(s);     dem++;     d[s] = 1;     while (!q.empty()) {       int u = q.front();       q.pop();       lt[dem].push_back(u);       for (vector<int>::iterator i = a[u].begin(); i != a[u].end(); i++) {         if (d[*i] == 0) {           d[*i] = 1;           q.push(*i);         }       }     }   }   void xuly(int k) {     priority_queue<int, vector<int>, greater<int> > q;     vector<int> t;     for (auto i : lt[k]) {       q.push(i);       t.push_back(id[i]);     }     sort(t.begin(), t.end());     for (auto i : t) {       c[i] = q.top();       q.pop();     }   }   int main() {     nhap();     for (int i = 1; i <= n; i++) {       if (d[i] == 0) {         bfs(i);       }     }     for (int i = 1; i <= dem; i++) {       xuly(i);     }     for (int i = 1; i <= n; i++) cout << c[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T a, T b) {     if (a == 0) return b;     return gcd(b % a, a);   }   template <typename T>   T pow(T a, T b, long long m) {     T ans = 1;     while (b > 0) {       if (b % 2 == 1) ans = (ans * a) % m;       b /= 2;       a = (a * a) % m;     }     return ans % m;   }   const long long N = 1e6 + 5;   long long n, m;   long long a[N], b[N], x[N], y[N];   map<long long, long long> ans;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> a[i] >> x[i];       ans[a[i]] = x[i];     }     cin >> m;     for (long long i = 1; i <= m; i++) {       cin >> b[i] >> y[i];       ans[b[i]] = max(ans[b[i]], y[i]);     }     long long answer = 0;     for (auto it : ans) answer += it.second;     cout << answer;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 2e5 + 888;   long long dp[maxn][12];   void solve() {     long long n;     scanf( %lld , &n);     memset(dp, -1, sizeof(dp));     dp[0][1] = 0;     vector<long long> v[4];     for (long long i = 1; i <= n; i++) {       for (long long j = 0; j < 4; j++) v[j].clear();       long long k;       scanf( %lld , &k);       while (k--) {         long long c, d;         scanf( %lld %lld , &c, &d);         v[c].push_back(d);       }       for (long long j = 1; j <= 3; j++) {         sort(v[j].begin(), v[j].end());         reverse(v[j].begin(), v[j].end());       }       for (long long prec = 0; prec <= 9; prec++) {         if (dp[i - 1][prec] < 0) continue;         long long val = LLONG_MIN / 10;         if (!v[1].empty()) val = max(val, v[1][0]);         if (!v[2].empty()) val = max(val, v[2][0]);         if (!v[3].empty()) val = max(val, v[3][0]);         if (prec == 0) val *= 2;         if (val > 0)           dp[i][(prec + 1) % 10] =               max(dp[i][(prec + 1) % 10], dp[i - 1][prec] + val);         val = LLONG_MIN / 10;         if (!v[1].empty() && !v[2].empty()) {           long long temp = v[1][0] + v[2][0];           long long mx = max(v[1][0], v[2][0]);           if (prec == 0 || prec == 9) temp += mx;           val = max(val, temp);         }         if (v[1].size() >= 2) {           long long temp = v[1][0] + v[1][1];           long long mx = max(v[1][0], v[1][1]);           if (prec == 0 || prec == 9) temp += mx;           val = max(val, temp);         }         if (val > 0)           dp[i][(prec + 2) % 10] =               max(dp[i][(prec + 2) % 10], dp[i - 1][prec] + val);         val = LLONG_MIN / 10;         if (v[1].size() >= 3) {           long long temp = v[1][0] + v[1][1] + v[1][2];           long long mx = max(v[1][0], max(v[1][2], v[1][1]));           if (prec == 0 || prec == 9 || prec == 8) temp += mx;           val = max(val, temp);         }         if (val > 0)           dp[i][(prec + 3) % 10] =               max(dp[i][(prec + 3) % 10], dp[i - 1][prec] + val);         dp[i][prec] = max(dp[i][prec], dp[i - 1][prec]);       }     }     long long ans = 0;     for (long long i = 0; i <= 9; i++) ans = max(ans, dp[n][i]);     cout << ans << endl;   }   signed main() { solve(); }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   unsigned long long bt[maxn];   unsigned long long d[maxn];   map<unsigned long long, int> has;   pair<int, int> edg[maxn];   int f[maxn];   int id[maxn];   int lab[maxn];   vector<int> e[maxn];   int vis[maxn];   int getf(int x) {     if (x == f[x])       return x;     else       return f[x] = getf(f[x]);   }   void dfs(int x, int y, int de) {     int i;     lab[x] = de;     vis[x] = 1;     for (i = 0; i < (int)e[x].size(); i++) {       if (e[x][i] == y) continue;       dfs(e[x][i], x, de + 1);     }   }   int main() {     int i, j, n, m;     cin >> n >> m;     int x, y;     bt[0] = 1;     for (int i = 1; i <= n; i++) {       bt[i] = 3 * bt[i - 1];       d[i] = bt[i];     }     for (i = 0; i < m; i++) {       scanf( %d%d , &x, &y);       edg[i] = make_pair(x, y);       d[x] += bt[y], d[y] += bt[x];     }     j = 1;     for (i = 1; i <= n; i++) {       if (!has[d[i]]) has[d[i]] = j++;       id[i] = has[d[i]];       f[i] = i;     }     for (i = 0; i < m; i++) {       x = id[edg[i].first], y = id[edg[i].second];       if (x == y) continue;       for (j = 0; j < (int)e[x].size(); j++) {         if (e[x][j] == y) break;       }       if (j >= 2) {         printf( NO n );         return 0;       }       if (j == (int)e[x].size())         e[x].push_back(y);       else         continue;       for (j = 0; j < (int)e[y].size(); j++) {         if (e[y][j] == x) break;       }       if (j >= 2) {         printf( NO n );         return 0;       }       if (j == (int)e[y].size())         e[y].push_back(x);       else         continue;       if (getf(x) == getf(y)) {         printf( NO n );         return 0;       } else         f[getf(y)] = f[getf(x)];     }     int cnt = 0;     for (i = 1; i <= n; i++) {       if (vis[id[i]] == 0 && (int)e[id[i]].size() < 2) {         vis[id[i]] = 1;         dfs(id[i], -1, 1);       }     }     printf( YES n );     for (i = 1; i <= n; i++) printf(i == n ?  %d n  :  %d  , lab[id[i]]);   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX_N = 2e5 + 5, inf = 1e18, mod = 1000000007;   const double PI = 3.1415926536;   int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   template <typename T>   ostream& operator<<(ostream& out, const vector<T>& mas) {     for (const auto& x : mas) {       out << x <<    ;     }     return out;   }   void ok() { cout <<  YES  <<   n ; }   void no() { cout <<  NO  <<   n ; }   inline long long nxt() {     long long x;     cin >> x;     return x;   }   struct Node {     vector<int> g;     long long sum = 0;     long long sum1 = 0;     void push(int v) { g.push_back(v); }     vector<int>::iterator begin() { return g.begin(); }     vector<int>::iterator end() { return g.end(); }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr), cout.tie(nullptr);     int n = nxt();     vector<Node> g(n);     vector<long long> a(n);     long long total = 0;     for (int i = 0; i < n; i++) {       a[i] = nxt();       total += a[i];     }     for (int i = 0; i < n - 1; i++) {       int v = nxt() - 1, u = nxt() - 1;       g[v].push(u);       g[u].push(v);     }     vector<int> lvl(n);     function<void(int, int)> dfs = [&](int v, int p) {       g[v].sum1 = a[v] * lvl[v];       g[v].sum = a[v];       for (const auto& to : g[v]) {         if (to != p) {           lvl[to] += lvl[v] + 1;           dfs(to, v);           g[v].sum += g[to].sum;           g[v].sum1 += g[to].sum1;         }       }     };     dfs(0, -1);     long long ans = 0;     long long res = g[0].sum1;     function<void(int, int)> calc = [&](int v, int p) {       ans = max(ans, res);       for (const auto& to : g[v]) {         if (to == p) continue;         g[v].sum -= g[to].sum;         res -= g[to].sum;         g[to].sum += g[v].sum;         res += g[v].sum;         calc(to, v);         res -= g[v].sum;         g[to].sum -= g[v].sum;         res += g[to].sum;         g[v].sum += g[to].sum;       }     };     calc(0, -1);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Mod = 1000000000 + 7;   const int MAXK = 1000000;   int power(int x, int k) {     int ret = 1;     while (k) {       if (k & 1) ret = 1LL * ret * x % Mod;       x = 1LL * x * x % Mod;       k >>= 1;     }     return ret;   }   int n, k, ans;   int f[MAXK + 10];   void init() {     cin >> n >> k;     if (n <= k + 10) {       for (int i = 1; i <= n; i++) ans = (power(i, k) + ans) % Mod;       cout << ans;     } else {       for (int i = 1; i <= k + 2; i++) f[i] = (f[i - 1] + power(i, k)) % Mod;       int s = 1, m = 1;       for (int j = 2; j <= k + 2; j++) s = 1LL * s * (n - j) % Mod;       for (int j = 2; j <= k + 2; j++) m = 1LL * m * ((1 - j) + Mod) % Mod;       int l = -(k + 1), r = 1;       for (int i = 1; i <= k + 2; i++) {         ans = (1LL * f[i] * s % Mod * power(m, Mod - 2) % Mod + ans) % Mod;         s = 1LL * s * (n - i) % Mod * power(n - (i + 1), Mod - 2) % Mod;         m = 1LL * m * r % Mod * power(l + Mod, Mod - 2) % Mod;         l++, r++;       }       cout << ans;     }     return;   }   int main() {     init();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const N = 202020;   long long a[N];   long long l[N], r[N];   int main() {     int n;     long long k;     scanf( %d%I64d , &n, &k);     for (int i = 1; i <= (n); ++i) scanf( %I64d , &a[i]);     for (int i = 1; i <= (n); ++i) l[i] = a[i - 1] == 1 ? 1 + l[i - 1] : 0;     for (int i = n; i >= 1; --i) r[i] = a[i + 1] == 1 ? 1 + r[i + 1] : 0;     long long mx = 0x3FFFFFFFFFFFFFFFLL;     long long ans = 0;     if (k == 1) {       for (int i = 1; i <= (n); ++i)         if (a[i] == 1) ++ans;     }     for (int i = 1; i <= (n); ++i)       if (a[i] != 1) {         long long ts = 0, tr = 1;         for (int j = i; j <= n; ++j) {           if (a[j] == 1) {             ts += r[j - 1];             j += r[j - 1];             j -= 1;             continue;           }           if (tr > mx / a[j]) break;           ts += a[j];           tr *= a[j];           if (tr % k == 0) {             long long need = tr / k - ts;             if (need >= 0) {               long long lc = min(need, l[i]), rc = min(need, r[j]);               long long cnt = lc + rc - need + 1;               cnt = max(cnt, 0LL);               ans += cnt;             }           }         }       }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int s = 0, ans = 0;     for (int i = 1;; i++) {       for (int j = 1; j <= i; j++) s += j;       if (s > n) break;       ans++;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void zanj0() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   void solve() {     int n, m;     cin >> n >> m;     int S = int(0.45 * sqrt(n)) + 1;     vector<int> v(n), rev_v(n), s_jump(n);     for (int i = 0; i < n; i++) {       cin >> v[i];       v[i]--;     }     for (int i = 0; i < n; i++) {       rev_v[v[i]] = i;     }     auto compute_s_jump = [&](int index) -> int {       int x = index;       for (int i = 0; i < S; i++) {         x = v[x];       }       return s_jump[index] = x;     };     for (int i = 0; i < n; i++) compute_s_jump(i);     while (m--) {       int type;       cin >> type;       if (type == 2) {         int x, k;         cin >> x >> k;         x--;         while (S <= k) {           k -= S;           x = s_jump[x];         }         while (k--) {           x = v[x];         }         cout << x + 1 <<   n ;       } else {         int x, y;         cin >> x >> y;         x--;         y--;         swap(rev_v[v[x]], rev_v[v[y]]);         swap(v[x], v[y]);         int sx = compute_s_jump(x);         int sy = compute_s_jump(y);         for (int i = 0; i < S; i++) {           s_jump[x] = sx;           s_jump[y] = sy;           x = rev_v[x];           y = rev_v[y];           sx = rev_v[sx];           sy = rev_v[sy];         }       }     }   }   int32_t main() {     zanj0();     solve();     cerr <<  Time :   << 1000 * (long double)clock() / (long double)CLOCKS_PER_SEC          <<  ms n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e6;   ;   int n, m, a, l, r, num;   int arr[2];   int main() {     scanf( %d%d , &n, &m);     while (n--) {       scanf( %d , &a);       if (a == -1)         ++arr[0];       else         ++arr[1];     }     while (m--) {       scanf( %d%d , &l, &r);       if (l == r) {         printf( 0 n );         continue;       }       num = r - l + 1;       if (num % 2 != 0)         printf( 0 n );       else {         if (num / 2 > arr[0] || num / 2 > arr[1])           printf( 0 n );         else           printf( 1 n );       }     }     return 0;   }