malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   vector<pair<int, int> > v;   struct Node {     Node *left, *right;     int val;     int lazy;     Node() {       left = right = NULL;       val = 0;       lazy = 0;     }   };   inline void refresh(Node*& root, int x, int y) {     if (root->lazy != 0 && root->val != (y - x + 1)) {       root->val = 1LL * (y - x + 1) * root->lazy;       if (x == y) {         root->lazy = 0;         return;       }       if (root->left == NULL) {         root->left = new Node();       }       if (root->right == NULL) {         root->right = new Node();       }       root->left->lazy = root->lazy;       root->right->lazy = root->lazy;       root->lazy = 0;     }   }   inline void update(Node*& root, int x, int y, int b, int e, int val) {     refresh(root, x, y);     if (x > e || y < b || (root->val == y - x + 1)) {       return;     }     int mid = (x + y) / 2;     if (x >= b && y <= e) {       root->lazy = val;       refresh(root, x, y);       return;     }     if (root->left == NULL) {       root->left = new Node();     }     if (root->right == NULL) {       root->right = new Node();     }     update(root->left, x, mid, b, e, val);     update(root->right, mid + 1, y, b, e, val);     root->val = root->left->val + root->right->val;   }   int query(Node*& root, int x, int y, int b, int e) {     if (root == NULL || x > e || y < b) {       return 0;     }     refresh(root, x, y);     if (x >= b && y <= e) {       return root->val;     }     int mid = (x + y) / 2;     int L = query(root->left, x, mid, b, e);     int R = query(root->right, mid + 1, y, b, e);     return L + R;   }   vector<pair<int, int> > Q[N];   int ans[N];   int main() {     Node* root = new Node();     int n;     scanf( %d , &n);     ;     for (int i = 0; i < n; i++) {       int x, y;       scanf( %d , &x);       ;       scanf( %d , &y);       ;       v.push_back(make_pair(x, y));     }     int q;     scanf( %d , &q);     ;     for (int i = 0; i < q; i++) {       int x, y;       scanf( %d%d , &x, &y);       Q[x].push_back(make_pair(y, i));     }     for (int i = v.size() - 1; i >= 0; i--) {       update(root, 1, 1000000007, v[i].first,              min(v[i].first + v[i].second - 1, 1000000007), 1);       for (auto x : Q[i + 1]) {         int a = i;         int b = x.first;         int len = v[b - 1].first - v[a].first;         ans[x.second] =             len - query(root, 1, 1000000007, v[a].first, v[b - 1].first - 1);       }     }     int y;     for (int i = 0; i < q; i++) {       printf( %d n , ans[i]);     }   }
/*       Washief Hossain Mugdho       20 December 2020       Codeforces 691F   */      #include <bits/stdc++.h>   #define ull unsigned long long   #define ll long long   #define pb push_back   #define mp make_pair   #define fr first   #define sc second   #define fastio ios_base::sync_with_stdio(0)   #define untie cin.tie(0)   #define ms(a, b) memset(a, b, sizeof a)   using namespace std;      void run_tests()   {       string s;       cin >> s;       vector<int> bam(2 * s.size() + 1, 0);       vector<int> dan(2 * s.size() + 1, 0);       int pos = s.size();       for (auto c : s)       {           if (c ==  0 )               dan[pos++]++;           else               bam[pos--]++;       }       pos = s.size();       while (bam[pos] + dan[pos])       {           if (dan[pos] && (!bam[pos] || bam[pos + 1]))           {               dan[pos++]--;               cout << 0;           }           else           {               bam[pos--]--;               cout << 1;           }       }       cout << endl;   }      int main()   {       fastio;       untie;   #ifdef LOCAL_OUTPUT       freopen(LOCAL_OUTPUT,  w , stdout);   #endif   #ifdef LOCAL_INPUT       freopen(LOCAL_INPUT,  r , stdin);   #endif          int tc;       cin >> tc;       while (tc--)           run_tests();   }
#include <bits/stdc++.h>   using namespace std;   long long cnt[19], val[19];   void init() {     cnt[1] = 9, cnt[2] = 9, cnt[3] = 90;     val[1] = 1, val[2] = 10, val[3] = 100;     long long t = 100;     for (int i = 4; i <= 19; i++)       cnt[i] = t * 9, t *= 10, val[i] = val[i - 1] * 10;   }   long long cal(long long a) {     long long bit = 0, tmp, p = a;     while (p) {       tmp = p;       p /= 10;       bit++;     }     long long ans = 0;     for (int i = 1; i <= bit - 1; i++) {       ans += cnt[i];     }     if (bit > 2)       ans += cnt[bit] / 9 * (tmp - 1);     else       ans += tmp - 1;     long long maxn;     long long minn = tmp;     for (int i = 1; i < bit; i++) {       minn *= 10;     }     minn += tmp;     maxn = a;     int mowei = a % 10;     if (mowei >= tmp)       maxn = maxn - mowei + tmp;     else if (maxn - 10 >= tmp * val[bit])       maxn = maxn - 10 - mowei + tmp;     else       return ans;     maxn = (maxn - tmp * val[bit]) / 10;     return maxn + 1 + ans;   }   int main() {     long long l, r;     while (~scanf( %I64d%I64d , &l, &r)) {       init();       long long a = cal(l), b = cal(r);       if (l < 10) a = l;       if (r < 10) b = r;       long long ans = b - a;       long long tmp1 = l % 10, tmp2;       while (l) {         tmp2 = l;         l /= 10;       }       if (tmp1 == tmp2) ans++;       printf( %I64d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void Display(vector<double> row) {     for (int i = 0; i < row.size(); i++) cout << row[i] <<    ;     cout << endl;   }   void Display(vector<vector<double> > matrix) {     for (int i = 0; i < matrix.size(); i++) Display(matrix[i]);     cout << endl;   }   vector<vector<double> > New(int n, int m, double x = 0.0) {     return vector<vector<double> >(n, vector<double>(m, x));   }   vector<vector<double> > Ident(int n) {     vector<vector<double> > Res = New(n, n);     for (int i = 0; i < n; i++) Res[i][i] = 1.0;     return Res;   }   void Multy(vector<vector<double> >& C, vector<vector<double> > A,              vector<vector<double> > B) {     assert(A[0].size() == B.size());     assert(A.size() == C.size());     assert(B[0].size() == C[0].size());     for (int i = 0; i < C.size(); i++)       for (int j = 0; j < C[0].size(); j++) C[i][j] = 0.0;     for (int i = 0; i < C.size(); i++)       for (int j = 0; j < C[0].size(); j++)         for (int k = 0; k < A[0].size(); k++) C[i][j] += A[i][k] * B[k][j];   }   const int N = 100100;   const int M = 4 * N;   const double Eps = 1e-6;   int n;   int a[N];   int b[N];   vector<vector<double> > Tree[M];   bool isZero(double x) { return abs(x) < Eps; }   void Merge(int Node) {     Multy(Tree[Node], Tree[(Node << 1)], Tree[(Node << 1 | 1)]);   }   void Build(int Node = 1, int L = 1, int R = n) {     Tree[Node] = New(2, 2);     if (L == R) {       int i = L;       Tree[Node][0][0] = 0.0;       Tree[Node][0][1] = 1.0 * (a[i] - b[i]) / a[i];       Tree[Node][1][0] = 1.0;       Tree[Node][1][1] = 1.0 * b[i] / a[i];       return;     }     Build((Node << 1), L, ((L + R) >> 1));     Build((Node << 1 | 1), ((L + R) >> 1) + 1, R);     Merge(Node);   }   void Update(int i, int Node = 1, int L = 1, int R = n) {     if (L == R) {       Tree[Node][0][0] = 0.0;       Tree[Node][0][1] = 1.0 * (a[i] - b[i]) / a[i];       Tree[Node][1][0] = 1.0;       Tree[Node][1][1] = 1.0 * b[i] / a[i];       return;     }     if (i <= ((L + R) >> 1))       Update(i, (Node << 1), L, ((L + R) >> 1));     else       Update(i, (Node << 1 | 1), ((L + R) >> 1) + 1, R);     Merge(Node);   }   void Query(vector<vector<double> >& Res, int i, int j, int Node = 1, int L = 1,              int R = n) {     if (i <= L && R <= j) return Multy(Res, Res, Tree[Node]);     if (j < L || R < i) return;     Query(Res, i, j, (Node << 1), L, ((L + R) >> 1));     Query(Res, i, j, (Node << 1 | 1), ((L + R) >> 1) + 1, R);   }   int main() {     int q;     cin >> n >> q;     for (int i = 1; i <= n; i++) scanf( %d%d , a + i, b + i);     Build();     while (q--) {       int T;       scanf( %d , &T);       if (T == 1) {         int i, x, y;         scanf( %d%d%d , &i, &x, &y);         a[i] = x;         b[i] = y;         Update(i);       } else {         int L, R;         scanf( %d%d , &L, &R);         vector<vector<double> > Res = Ident(2);         Query(Res, L, R);         double Ans = 1.0 / Res[1][1];         if (Ans != Ans) Ans = 0.0;         printf( %.10f n , Ans);       }     }   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, a[500050], R[500050];   int main() {     n = read();     for (int i = 1; i <= n; i++) {       a[i] = read();       if (i <= n - i + 1) R[i] = n - i + 1, R[n - i + 1] = i;     }     int cnt = 0;     for (int i = 1; i <= n - i + 1; i++) {       cnt++;       if (cnt & 1) swap(a[i], a[R[i]]);     }     for (int i = 1; i <= n; i++) printf( %d  , a[i]);   }
#include <bits/stdc++.h>   using namespace std;   string s;   void rev() {     for (int i = 0; i < s.size(); i++)       if (s[i] ==  L )         s[i] =  R ;       else         s[i] =  L ;   }   vector<int> v;   int k[2000011];   const int delta = 1000005;   bool verify(int nr) {     memset(k, 0, sizeof(k));     int now = 0;     k[now + delta]++;     for (int i = 0; i < v.size(); i++) {       now = min(nr - 1, now + v[i]);       k[now + delta]++;     }     if (k[now + delta] > 1) return false;     return true;   }   int i, sum, mx, l, r, mid, ans;   int main(void) {     cin >> s;     if (s[s.size() - 1] ==  R ) rev();     for (i = 0; i < s.size(); i++) {       if (s[i] ==  R )         v.push_back(1);       else         v.push_back(-1);       sum += v[i];       mx = max(mx, sum);     }     if (verify(mx + 2)) {       cout << 1;       return 0;     }     l = 1;     r = mx;     while (l <= r) {       mid = (l + r) / 2;       if (verify(mid) == true) {         ans = mid;         l = mid + 1;       } else         r = mid - 1;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 2;   long long n, a[maxn], k, ans[maxn];   long long Check(long long m) {     long long res = 0, l, r, mid;     for (int i = 1; i <= n; i++) {       l = 1;       r = a[i];       while (l <= r) {         mid = (l + r) / 2;         if (a[i] - 3 * mid * (mid + 1) - 1 >= m)           l = mid + 1;         else           r = mid - 1;       }       ans[i] = r;       res += r;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     long long l = -4e18, r = 4e18, mid;     while (l <= r) {       mid = (l + r) / 2;       if (Check(mid) >= k)         l = mid + 1;       else         r = mid - 1;     }     long long sum = Check(l);     for (int i = 1; i <= n; i++)       if (sum < k && ans[i] < a[i] &&           a[i] - 3 * (ans[i] + 1) * (ans[i] + 2) - 1 == l - 1) {         sum++;         ans[i]++;       }     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int k;   bool debug = false;   int f[100005];   int ff(int x) {     while (x != f[x]) x = f[x];     return x;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) f[i] = i;     int a, b;     long long ans = 1;     for (int i = 0; i < m; i++) {       scanf( %d%d , &a, &b);       int fa = ff(a), fb = ff(b);       if (fa == fb) {         ans = ans * 2 % 1000000009;       } else {         f[fa] = fb;       }       printf( %I64d n , ans - 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int nn, n, b, q;   vector<pair<int, int> > d;   int main() {     d.push_back(make_pair(0, 0));     scanf( %d%d%d , &n, &b, &q), nn = n;     d.push_back(make_pair(b, n));     for (int i = 1; i <= q; i++)       scanf( %d%d , &b, &n), d.push_back(make_pair(b, n));     sort(d.begin(), d.end());     for (int i = 1; i <= q; i++)       if (d[i].second > d[i + 1].second ||           d[i + 1].second - d[i].second > d[i + 1].first - d[i].first)         return printf( unfair n ), 0;     for (int k = 0; k < 32; k++) {       int res = 0;       for (int i = 1; i <= q + 1; i++) {         int cnt = 0;         for (int j = d[i - 1].first + 1; j <= d[i].first; j++)           cnt += bool((1 << (j % 5)) & k);         res += min(cnt, d[i].second - d[i - 1].second);       }       if (res < nn / 5 * __builtin_popcount(k)) return printf( unfair n ), 0;     }     printf( fair n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 0;   const int LOGN = 0;   const int MOD = 1e9 + 7;   const int INF = 1e9 + 10;   long long N, Q;   long long x;   long long f(long long x) {     if (x & 1) return (x + 1) >> 1;     long long id = N - (x >> 1);     while (!(id & 1)) id >>= 1;     id >>= 1;     return N - id;   }   void read() {     cin >> N >> Q;     while (Q--) {       cin >> x;       cout << f(x) <<   n ;     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     read();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long GCD(long long a, long long b) {     if (b) return GCD(b, a % b);     return a;   }   bool u1[10];   bool u2[10];   int main() {     long long n, m, v;     vector<long long> a, b;     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (long long i = 0; i < n; i++) {       cin >> v;       a.push_back(v);       u1[v] = true;     }     for (long long i = 0; i < m; i++) {       cin >> v;       b.push_back(v);       u2[v] = true;     }     sort(a.begin(), a.end());     sort(b.begin(), b.end());     for (long long i = 1; i <= 9; i++) {       if (u1[i] && u2[i]) {         cout << i;         return 0;       }     }     if (a[0] < b[0]) {       cout << a[0] << b[0];     } else       cout << b[0] << a[0];   }
#include <bits/stdc++.h>   using namespace std;      /*<DEBUG>*/   #define tem template <typename    #define can_shift(_X_, ...) enable_if_t<sizeof test<_X_>(0) __VA_ARGS__ 8, debug&> operator<<(T i)   #define _op debug& operator<<   tem C > auto test(C *x) -> decltype(cerr << *x, 0LL);   tem C > char test(...);   tem C > struct itr{C begin, end; };   tem C > itr<C> get_range(C b, C e) { return itr<C>{b, e}; }   struct debug{   #ifdef _LOCAL    ~debug(){ cerr << endl; }    tem T > can_shift(T, ==){ cerr << boolalpha << i; return *this; }    tem T> can_shift(T, !=){ return *this << get_range(begin(i), end(i)); }    tem T, typename U > _op (pair<T, U> i){      return *this <<  <   << i.first <<   ,   << i.second <<   > ; }    tem T> _op (itr<T> i){     *this <<   {  ;     for(auto it = i.begin; it != i.end; it++){      *this <<   ,   + (it==i.begin?2:0) << *it;     }     return *this <<   } ;    }   #else   tem T> _op (const T&) { return *this; }   #endif    };      string _ARR_(int* arr, int sz){    string ret =  {   + to_string(arr[0]);     for(int i = 1; i < sz; i++) ret +=   ,   +  to_string(arr[i]);    ret +=   } ; return ret;   }      #define exp(...)   [   << #__VA_ARGS__ <<   :   << (__VA_ARGS__) <<   ]    /*</DEBUG>*/      typedef long long ll;   typedef unsigned long long ull;   typedef unsigned int uint;   typedef pair<int, int> pii;   //mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());      #define pb push_back   #define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)   #define TC int __TC__; cin >> __TC__; while(__TC__--)   #define ar array      const int INF = 1e9 + 7;      int main(void)   {    FAST;    vector<ll> mx;    for(ll i = 1; i*i + (i+1)*(i+1) <= INF; ++i){     mx.pb(i*i + (i+1) * (i+1));    }       TC{     int n; cin >> n;     int pos = (lower_bound(mx.begin(), mx.end(), n) - mx.begin());     if(mx[pos] == n) ++pos;     cout << pos <<   n ;    }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long n, k;     cin >> n >> k;     vector<long long> occ(255);     string s;     cin >> s;     long long streak = 0;     char curr = s[0];     for (long long i = 0; i < n; i++) {       if (s[i] == curr) {         streak++;         if (streak == k) {           occ[curr]++;           streak = 0;         }       } else {         streak = 1;         curr = s[i];       }     }     long long mx = 0;     for (long long i = 0; i < 255; i++) {       mx = max(occ[i], mx);     }     cout << mx << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const int MOD = 1e9 + 7;   template <typename Tp>   void read(Tp &x) {     x = 0;     int op = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) op = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     x *= op;   }   template <typename Tp>   void CMax(Tp &x, Tp y) {     if (y > x) x = y;   }   template <typename Tp>   void CMin(Tp &x, Tp y) {     if (y < x) x = y;   }   int n, m, a[N], mx;   int f[N], res1, res2, ans;   void norm(int &x) {     while (x >= MOD) x -= MOD;     while (x < 0) x += MOD;   }   int Inv(int x, int p = MOD - 2) {     int ret = 1;     while (p) {       if (p & 1) ret = 1ll * ret * x % MOD;       x = 1ll * x * x % MOD;       p >>= 1;     }     return ret;   }   int main() {     read(n);     for (int i = (1); i <= (n); ++i) read(a[i]), m += a[i], CMax(mx, a[i]);     ans = 1ll * m * (m - 1) % MOD;     for (int i = (1); i <= (mx); ++i) {       res1 += res2;       norm(res1);       int v = Inv(i - 1 - m + MOD);       res2 += v;       norm(res2);       res1 += v;       norm(res1);       f[i] = 1ll * res1 * (m - 1) % MOD;       norm(f[i]);     }     for (int i = (1); i <= (n); ++i) ans += f[a[i]], norm(ans);     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int SIZE = 1 << 17;   char buffer[SIZE];   int pointer = SIZE;   char Advance() {     if (pointer == SIZE) {       fread(buffer, 1, SIZE, stdin);       pointer = 0;     }     return buffer[pointer++];   }   int Read() {     int answer = 0;     char ch = Advance();     while (!isdigit(ch)) ch = Advance();     while (isdigit(ch)) {       answer = answer * 10 + ch -  0 ;       ch = Advance();     }     return answer;   }   const int MAXN = 100000;   const int MAXQ = 200000;   const int MAXNODES = 262144;   struct Point {     int x;     int y;     bool operator<(const Point &other) const { return x < other.x; }   };   Point v[1 + MAXQ];   struct Query {     Point a;     Point b;     int index;     bool operator<(const Query &other) const { return b < other.b; };   };   Query query[1 + MAXQ];   bool ok[1 + MAXQ];   int tree[1 + MAXNODES], where, from, to, change;   void Update(int node, int left, int right) {     if (left == right) {       tree[node] = change;       return;     }     int middle = (left + right) / 2;     if (where <= middle)       Update(2 * node, left, middle);     else       Update(2 * node + 1, middle + 1, right);     tree[node] = min(tree[2 * node], tree[2 * node + 1]);   }   int Query(int node, int left, int right) {     if (from <= left && right <= to) return tree[node];     int answer = MAXN, middle = (left + right) / 2;     if (from <= middle) answer = min(answer, Query(2 * node, left, middle));     if (middle + 1 <= to)       answer = min(answer, Query(2 * node + 1, middle + 1, right));     return answer;   }   void Solve(int k, int q, int n, int m) {     sort(v + 1, v + k + 1);     sort(query + 1, query + q + 1);     for (int i = 1, j = 1; i <= q; i++) {       while (j <= k && v[j].x <= query[i].b.x) {         where = v[j].y;         change = v[j].x;         Update(1, 1, m);         j++;       }       from = query[i].a.y;       to = query[i].b.y;       if (Query(1, 1, m) >= query[i].a.x) ok[query[i].index] = true;     }   }   int main() {     int n = Read(), m = Read(), k = Read(), q = Read();     for (int i = 1; i <= k; i++) {       v[i].x = Read();       v[i].y = Read();     }     for (int i = 1; i <= q; i++) {       query[i].a.x = Read();       query[i].a.y = Read();       query[i].b.x = Read();       query[i].b.y = Read();       query[i].index = i;     }     Solve(k, q, n, m);     for (int i = 1; i <= k; i++) swap(v[i].x, v[i].y);     memset(tree, 0, sizeof(tree));     for (int i = 1; i <= q; i++) {       swap(query[i].a.x, query[i].a.y);       swap(query[i].b.x, query[i].b.y);     }     Solve(k, q, m, n);     for (int i = 1; i <= q; i++)       if (ok[i])         printf( YES n );       else         printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d%d , &n, &m);     ;     int cnt = 0;     for (int i = 0; i < (n + 1); i++)       for (int j = 0; j < (n + 1); j++) {         if (i * i + j == n && i + j * j == m) cnt++;       }     printf( %d n , cnt);   }
#include <bits/stdc++.h>   using namespace std;   int N, ans = 0, overtake = 0, pspeed, plimit = 1000;   stack<int> signs;   int main() {     cin >> N;     for (int i = 0, a, b; i < N; i++) {       cin >> a;       if (a == 1) {         cin >> b;         pspeed = b;         while (!signs.empty()) {           if (signs.top() < b) {             ans++;             signs.pop();           } else {             break;           }         }       } else if (a == 2) {         if (overtake > 0) {           ans += overtake;           overtake = 0;         }       } else if (a == 3) {         cin >> b;         signs.push(b);         while (!signs.empty()) {           if (signs.top() < pspeed) {             ans++;             signs.pop();           } else {             break;           }         }       } else if (a == 4) {         overtake = 0;       } else if (a == 5) {         while (!signs.empty()) signs.pop();       } else {         overtake++;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long N = 1e6 + 5;   const long long inf = 1e18;   long long powermod(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;   loop:     while (t--) {       long long n;       cin >> n;       long long x = n / 4;       if (n % 4 != 0) x++;       n -= x;       while (n--) {         cout << 9;       }       while (x--) cout << 8;       cout <<   n ;     }     return 0;   }