๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.65K subscribers
5.62K photos
3 videos
95 files
10.8K links
๐ŸšฉMain Group - @SuperExams
๐Ÿ“Job Updates - @FresherEarth

๐Ÿ”ฐAuthentic Coding Solutions(with Outputs)
โš ๏ธDaily Job Updates
โš ๏ธHackathon Updates & Solutions

Buy ads: https://telega.io/c/cs_algo
Download Telegram
#include <bits/stdc++.h>
using namespace std;
long long comb(int n, int r) {
    if (r > n) return 0;
    if (r == 0 || r == n) return 1;
    long long res = 1;
    for (int i = 0; i < r; i++) {
        res = res * (n - i) / (i + 1);
    }
    return res;
}
long long Balanced(int A, int B, int C) {
    long long s = 0;
    for (int p = 4; p <= min(A, C - 1); p++) {
    int w = C - p;
    if (w >= 1 && w <= B) {
    s += comb(A, p) * comb(B, w);
        }
    }
    return s;
} // Balance Mixture
โœ…
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int gap(char a, char b) {
    return abs(a - b);
}
string longestKInterspaceSubstring( string &word, int k) {
    string temp = "", maxSubstring = "";
    for (size_t i = 0; i < word.length(); i++) {
    temp += word[i];
    if (i < word.length() - 1 && gap(word[i], word[i + 1]) > k) {
    if (temp.length() > maxSubstring.length()) {
    maxSubstring = temp;
    }
    temp = "";
        }
    }
    if (temp.length() > maxSubstring.length()) {
        maxSubstring = temp;
    }

    return maxSubstring;
}


Longest K intersapace substring โœ…
Paypal
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
using namespace std;
const int MOD = 1000000007;

struct node {
    int val;
    int lazy;
    node *left;
    node *right;

    node() {
        left = nullptr;
        right = nullptr;
        lazy = 0;
        val = 0;
    }
};

void build(node *&root, int s, int e) {
    root = new node();
    if (s == e) {
        root->val = 0;
    } else {
        int mid = (s + e) / 2;
        build(root->left, s, mid);
        build(root->right, mid + 1, e);
        root->val = root->left->val + root->right->val;
    }
}

void applyLazy(node* root, int s, int e) {
    if (root->lazy) {
        root->val = (e - s + 1) - root->val;
        if (s != e) {
            if (!root->left) root->left = new node();
            if (!root->right) root->right = new node();
            root->left->lazy ^= 1;
            root->right->lazy ^= 1;
        }
        root->lazy = 0;
    }
}

void update_range(node *root, int s, int e, int l, int r) {
    applyLazy(root, s, e);
    if (s > r || e < l) return;
    if (s >= l && e <= r) {
        root->lazy ^= 1;
        applyLazy(root, s, e);
        return;
    }
    int mid = (s + e) / 2;
    update_range(root->left, s, mid, l, r);
    update_range(root->right, mid + 1, e, l, r);
    root->val = root->left->val + root->right->val;
}

int query(node *root, int s, int e, int l, int r) {
    applyLazy(root, s, e);
    if (s > r || e < l) return 0;
    if (s >= l && e <= r) {
        return root->val;
    }
    int mid = (s + e) / 2;
    int leftQuery = query(root->left, s, mid, l, r);
    int rightQuery = query(root->right, mid + 1, e, l, r);
    return leftQuery + rightQuery;
}

int solve(int N, vector<vector<int>>& B) {
    node* root = nullptr;
    build(root, 0, N - 1);
   
    int sumQueries = 0;
    for (const auto& op : B) {
        int type = op[0];
        int l = op[1] - 1;
        int r = op[2] - 1;

        if (type == 0) {
            update_range(root, 0, N - 1, l, r);
        } else {
            sumQueries += query(root, 0, N - 1, l, r);
            sumQueries %= MOD;
        }
    }
    return sumQueries;
}

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<vector<int>> B(Q, vector<int>(3));
   
    for (int i = 0; i < Q; ++i) {
        cin >> B[i][0] >> B[i][1] >> B[i][2];
    }

    int result = solve(N, B);
    cout << result << endl;

    return 0;
}


Mask updates
Media. Netโœ…
๐Ÿ‘1
#include <bits/stdc++.h>
using namespace std;
void solve() {
    int T;
    cin >> T;
    while (T--) {
        int n, x;
        cin >> n >> x;
        vector<int> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        vector<int> remainderCount(x, 0);
        for (int i = 0; i < n; i++) {
            remainderCount[a[i] % x]++;
        }
        int pairs = 0;
        pairs += remainderCount[0] / 2;
        for (int r = 1; r <= x / 2; r++) {
            if (r == x - r) {
                pairs += remainderCount[r] / 2;
            } else {
                int minCount = min(remainderCount[r], remainderCount[x - r]);
                pairs += minCount;
                remainderCount[r] -= minCount;
                remainderCount[x - r] -= minCount;
            }
        }
        cout << pairs * 2 << endl;
    }
}

int main() {
    solve();
    return 0;
}


christmas celebration โœ