๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.61K subscribers
5.59K photos
3 videos
95 files
10.2K 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
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <bits/stdc++.h>
using namespace std;
struct ST {
    int n;
    vector<long long> t, lz;
    ST(int sz) {
        n = sz;
        t.resize(4 * n, 0);
        lz.resize(4 * n, 0);
    }
    void p(int nd, int s, int e) {
    if (lz[nd] != 0) {
    t[nd] += lz[nd];
    if (s != e) {
    lz[2 * nd + 1] += lz[nd];
    lz[2 * nd + 2] += lz[nd];
    }
    lz[nd] = 0;
    }
    }
    void ru(int nd, int s, int e, int l, int r, long long v) {
    p(nd, s, e);
    if (s > r || e < l) return;
    if (s >= l && e <= r) {
    lz[nd] += v;
    p(nd, s, e);
    return;
    }
    int m = (s + e) / 2;
    ru(2 * nd + 1, s, m, l, r, v);
    ru(2 * nd + 2, m + 1, e, l, r, v);
    t[nd] = max(t[2 * nd + 1], t[2 * nd + 2]);
    }
long long rq(int nd, int s, int e, int l, int r) {
p(nd, s, e);
if (s > r || e < l) return 0;
if (s >= l && e <= r) return t[nd];
int m = (s + e) / 2;
return max(rq(2 * nd + 1, s, m, l, r), rq(2 * nd + 2, m + 1, e, l, r));
}

void u(int l, int r, long long v) {
ru(0, 0, n - 1, l, r, v);
    }

    long long q(int l, int r) {
        return rq(0, 0, n - 1, l, r);
    }
};

long long SkillUpdate(int n, int q, vector<tuple<int, int, int>>& u) {
    ST st(n);
    vector<long long> mx(q, 0);
    for (auto& [l, r, x] : u) {
        st.u(l - 1, r - 1, x);
    }

    for (int i = 0; i < q; i++)
    {
        auto [l, r, x] = u[i];
        st.u(l - 1, r - 1, -x);
        mx[i] = st.q(0, n - 1);
        st.u(l - 1, r - 1, x);
    }

    return *min_element(mx.begin(), mx.end());
}

Minimize and Maximumโœ…
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
     int n;
     cin>>n;
     vector<int>arr(n);
     for(int i=0;i<n;i++)cin>>arr[i];
     vector<int>presum(n);
     presum[0]=arr[0];
     for(int i=1;i<n;i++)presum[i]=presum[i-1]+arr[i];
     vector<int>dp(n);
     vector<int>val(n);
     dp[0]=1;
     val[0]=arr[0];

     for(int i=1;i<n;i++){
       
        int l=0,h=i;
        int ind=0;
        while(h>=l){
          int mid=(l+h)/2;
          int sum= presum[i]- (mid>0?presum[mid-1]:0);
          int prev = (mid>0?val[mid-1]:0);
          if(sum>=prev){
            ind=mid;
            l=mid+1;
          }
          else h=mid-1;
        }
        if(ind==0){
          dp[i]=1;
          val[i]=presum[i];
        }
        else{
          dp[i]=dp[ind-1]+1;
          val[i]=presum[i]-presum[ind-1];
        }
     }
     cout<<dp.back();
}
 
Operate the subarrayโœ…
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
using namespace std;
string LexicographicOrder(string S) {
string result = "";
while (!S.empty()) {
set<char> seen;
string uniqueChars = "";
for (char c : S) {
if (seen.find(c) == seen.end()) {
uniqueChars += c;
seen.insert(c);
            }
        }
sort(uniqueChars.begin(), uniqueChars.end());
result += uniqueChars;
for (char c : uniqueChars) {
size_t pos = S.find(c);
if (pos != string::npos) {
S.erase(pos, 1);
            }
        }
    }
    return result;
}


Tiger Analytics โœ