Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

LL1 Query in array Simple Divison Subsequence Holi

#include <iostream> #include<iostream> #include<iostream>


using namespace std; using namespace std; using namespace std; #include<iostream>
#include<iostream>
int main() using namespace std; int main() using namespace std;
{ int main() { int main()
struct Node { int n,q; int t;
{ {
int data; cin>>n>>q; int t,n,x,y; cin>>t; int t;
struct Node* next; int arr[n]; int i; while(t--) cin >> t;
Node(int x){ for(int i=0;i<n;i++) cin>>t; { while(t--)
{ while(t--) int n; {
data = x;
cin>>arr[i]; { cin>>n; long long n, k, min;
next = nullptr; } int count=0; int arr[n]; cin >> n >> k;
} for(int i=0;i<q;i++) cin>>n>>x>>y; for(int i=0;i<n;i++) long long r[n], d[n];
}; { int arr[n]; { for(int i=0; i<n; i++)
int getNthNodeFromEnd(struct Node* head, int n){ int l,r,x; for(i=0;i<n;i++) cin>>arr[i]; {
{ } cin >> d[i];
struct Node* temp = head; cin>>arr[i];
cin>>l>>r>>x; int odd=0, even=0; }
int size = 0; int m=l-1; if(arr[i]<=x && arr[i]%y==0) for(int i=1;i<n;i=i+2) cin>> r[0];
while(temp){ int n=r-1; { { min = r[0] + d[0]*k;
temp = temp->next; int mid; count++; odd=odd+arr[i];
} for(int i=1; i<n; i++)
size++; while(m<=n)
}
} {
} { for(int i=0;i<n;i=i+2) cin >> r[i];
cout<<count<<endl;
mid=(m+n)/2; { if(min > (r[i] + d[i]*k))
int pos = size - n; }
if(arr[mid]>=x) return 0; even=even+arr[i]; {
temp = head; { }
} min = r[i] + d[i]*k;
while(pos > 0){ n=mid-1; if(even>odd) }
temp = temp->next; } Knapsack { }
pos--; else #include<iostream> cout<<even<<endl; cout << min << endl;
} { using namespace std; }else }
m=mid+1; int main() { return 0;
return temp->data; } cout<<odd<<endl;
{ }
} } }
int t;
cout<<r-m<<endl; cin >> t; }
LL2 } while(t-- > 0) return 0;
struct Node return 0; { }
{ } int i, c, k;
int data; Balanced String Parentheses
cin >> i >> c >> k;
struct Node *next; #include <bits/stdc++.h>
Can Swap long int w[i];
using namespace std;
Node() for(int n = 0; n < i; n++)
#include <iostream> bool isValid(string s)
{ cin >> w[n];
#include <bits/stdc++.h> {
next = NULL; int max = 0, count = 0;
#include <string.h> int n = s.size();
} for(int n = 0; n < i; n++)
using namespace std; stack<char> st;
Node(int x) {
int main() { bool ans = true;
{ int sum1 = 0;
int t; for (int i = 0; i < n; i++)
data = x;
next = NULL;
cin>>t; { for(int j = n; j < i ; j++) {
while(t--)
} if (s[i] == '{' || s[i] == '[' || s[i] == '(')
{ sum1 += w[j];
}; {
int i,n; if(sum1 >= k && sum1 <= c && ((j - n) + 1) > count)
cin>>n; count = ((j - n) + 1); } st.push(s[i]);
Node *merge(Node *head1, Node *head2) char a[n]; if(sum1 > c) else if (s[i] == ')')
{ char b[n]; break; {
Node *head = NULL; for(i=0;i<n;i++) } if (!st.empty() && st.top() == '(')
if (head1 == NULL) { } {
{ cin>>a[i]; cout << count << endl; st.pop();
return head2; } } }
} for(i=0;i<n;i++) return 0; else
else if (head2 == NULL) { } {
{ b[i]=a[i]; ans = false;
return head1; } break;
} sort(a,a+i); }
int count=0; Count distinct numbers }
if (head1->data <= head2->data) for(i=0;i<n;i++) #include<iostream> else if (s[i] == '}')
{ { using namespace std; {
head = head1; if(a[i]!=b[i]) int main() if (!st.empty() && st.top() == '{')
head->next = merge(head1->next, head2); count++; { {
} } int t,n,k,ctr; st.pop();
else if(count<3) int a[100]; }
{ cout<< "YES"<<endl; cin>>t; else
head = head2; else while(t!=0) {
head->next = merge(head1, head2->next); cout<< "NO"<<endl; { ans = false;
} } ctr=0; break;
return 0; cin>>n; }
return head; } cin>>k; }
} for(int i=0;i<n;i++)
{ else if (s[i] == ']')
cin>>a[i]; {
Students and fighting 2nd insertion if (!st.empty() && st.top() == '[')
#include <bits/stdc++.h> }
#include<bits/stdc++.h> {
using namespace std; int l=0;
using namespace std; st.pop();
int main() while(l!=n-k+1)
int main() }
{ {
{ else
int t; for(l;l<l+k;l++)
int n; {
cin >> t; {
cin>>n; ans = false;
while (t--) int a[n]; break;
{ for(int j=l+1;j<l+k;j++)
{ }
int n; for (int i = 0; i < n; i++) }
cin >> n; if(a[l]!=a[j])
{ }
int a[n]; {
cin>>a[i]; return ans;
int count = 0; ctr++;
} }
} int main()
for (int i = 0; i < n; i++) }
for(int i=1;i<n;i++) {
{ }
{ int t;
cin >> a[i]; cout<<ctr<<" ";
int current=a[i]; cin >> t;
} l++;
int j=i-1; while (t--)
sort(a, a + n); }
while (a[j]>current && j>=0) {
t--;
{ string s;
int ans = *max_element(a, a + n); }
a[j+1]=a[j]; cin >> s;
return 0;
j--; if (isValid(s))
if (a[n - 2] < ans) }
} {
{ cout << "1" << endl;
cout << "peace:)" << endl; a[j+1]=current; }
} else
else if (a[n - 2] == ans) } {
{ for (int i = 0; i < n; i++) cout << "0" << endl;
cout << "fight:(" << endl; { }
} cout<<a[i]<<" "; }
} } return 0;
return 0; return 0; }
} }
ll with queue
Optimal adjacent removal Longest subarray Maximum Difference 1st bubble #include<bits/stdc++.h>
#include <iostream> #include <iostream> #include <iostream> #include<bits/stdc++.h> using namespace std;
#include <stack> using namespace std; #include <limits.h> using namespace std;
using namespace std; int main() { using namespace std; class node{
int MinimumLength(string s) // your code goes here int main() { int main() public:
{ int T; int T; {
int data;
int len = s.length(); cin>>T; cin>>T;
node *next;
stack<char> mystack; while(T--) while(T--) int n;
mystack.push(s[0]); { { cin>>n;
node(int data){
for (int i = 1; i < len; i++) int N; int N,M; int a[n];
this->data=data;
{ cin>>N; cin>>N>>M;
this->next=NULL;
if (s[i] >= 'a' && s[i] <= 'z') int A[N]; int a[N][M]; for (int i = 0; i < n; i++)
}
{ for(int i=0;i<N;i++) {
};
{ int D; cin>>a[i];
if (mystack.empty()) cin>>A[i]; int ans=0;
class Queue{
{ } for(int i=0;i<N;i++) }
public:
mystack.push(s[i]); int evencnt,maxcnt=0; {
node *front=NULL,*rear=NULL;
} for(int i=0;i<N;i++) for(int j=0;j<M;j++) int count=1; Queue(){
else { { int c=0; this->front=NULL;
{ evencnt=0; cin>>a[i][j]; this->rear=NULL;
if (s[i] == mystack.top()) for(int j=i;j<N;j++) } while(count<n){ }
{ { } for(int i=0;i<n-count;i++)
mystack.pop(); if(A[j]%2==0) for(int i=0;i<N;i++) { void push(int data){
} { { node *newnode=new node(data);
else evencnt+=1; int max = INT_MIN; if(a[i]>a[i+1]) if(this->front==NULL){
{ } int min = INT_MAX; { this->front=newnode;
mystack.push(s[i]); else for(int j=0;j<M;j++) this->rear=newnode;
} { { int temp=a[i+1]; }
} break; if(a[i][j]<min) a[i+1] =a[i]; else{
} } { a[i]=temp; this->rear->next=newnode;
} } min=a[i][j]; c++; this->rear=newnode;
return mystack.size(); if(evencnt>maxcnt) } } }
} { if(a[i][j]>max)
int main() maxcnt=evencnt; { } }
{ } max=a[i][j]; count++;
int T; } } } void pop(){
cin >> T; cout<<maxcnt<<endl; if(this->front==NULL){
while (T--) } } for (int i = 0; i < n; i++) cout<<"\nQueue is empty";
{ return 0; D = max - min; { }
string s; } if(D>ans){ cout<<a[i]<<" "; else{
cin >> s; ans = D; } node *temp=this->front;
int result; } if(c<=1){ this->front=this->front->next;
result = MinimumLength(s); } cout<<"Yes"<<c<<endl; delete temp;
cout << result << endl; cout<<ans<<endl; } }
} } else
}
return 0; return 0; cout<<"NO"<<c<<endl;
void peek(){
} } return 0;
if(this->front==NULL){
}
cout<<"\nQueue is empty";
Largest Subpermutation Maximum Overlap }
#include <bits/stdc++.h> #include<iostream> Non Repeating Array 3rd merge else
using namespace std; #include<bits/stdc++.h> #include<iostream> #include <bits/stdc++.h> {
bool isPermutation(int a[], int b[], int n, #define ll long long int using namespace std; using namespace std; cout<<this->front->data;
int start, int end) using namespace std; void merge(int arr[], int l, int mid, int r) }
{ void overlap(vector<pair<ll,ll>> v){ int main() { }
int len = end - start + 1; ll ans = 0; int n1 = mid - l + 1;
{ bool empty(){
int n2 = r - mid;
int x[len], y[len]; ll count = 0; int T; if(front==NULL){
for (int i = 0; i < len; i++) vector<pair<ll, char>> data; cin>>T; int a[n1]; return true;
for (ll i=0;i<v.size();i++){ while(T--) int b[n2]; // temp }
{ data.push_back({v[i].first,'x'}); { else{
x[i] = a[start + i]; data.push_back({v[i].second,'y'}); int N; for (int i = 0; i < n1; i++) return false;
y[i] = b[start + i]; } // Number of elements { }
sort(data.begin(),data.end()); cin>>N; a[i] = arr[l + i]; }
} for (ll i=0;i<data.size();i++){ int arr[N]; }
sort(x, x + len); if (data[i].second=='x'){ int listInd = 0; for (int i = 0; i < n2; i++) };
sort(y, y + len); count++; {
for(int i=0;i<N;i++) int main(){
b[i] = arr[mid + 1 + i];
bool isEqual = true; } { }
for (int i = 0; i < len; i++) if (data[i].second == 'y'){ cin>>arr[i]; int i = 0; Queue q;
count--; if(i!=0 && listInd!=-2 && int j = 0; q.push(1);
{ } arr[listInd]==arr[i]){ q.push(2);
if (x[i] != y[i]) ans = max(ans, count); listInd+=1; //1 i=1 int k = l; q.push(3);
} for(int j=0;j<=i;j++){ while (i < n1 && j < n2) q.pop();
{ cout << ans << endl; if(listInd==j){ { q.peek();
isEqual = false; } if(listInd==i){ if (a[i] < b[j]) return 0;
break; int main(){ listInd = -2; { }
ll T; arr[k] = a[i];
}
k++;
} cin >> T; continue; i++;
while(T--){ } }
} ll n; if(arr[listInd]==arr[j]){ else
cin >> n; if(listInd==i){ {
if (isEqual) ll m; listInd = -2; arr[k] = b[j];
return true; cin >> m; break; k++;
else return false; vector<pair<ll,ll>> A; } j++;
} for(ll i=0;i<n;i++){ listInd+=1; }
void runTestCase() ll l,r; j=0; }
{ cin >> l >> r; while (i < n1)
}
{
int N; A.push_back({l,r}); } arr[k] = a[i];
cin >> N; } cout<<listInd+1<<" "; k++;
int A[N], B[N]; overlap(A); } i++;
for (int i = 0; i < N; i++) } else if(listInd==-2){ }
cin >> A[i]; return 0; listInd = i; while (j < n2)
for (int i = 0; i < N; i++) } for(int j=0;j<i;j++){ {
cin >> B[i]; if(arr[i]==arr[j]){ arr[k] = b[j];
int count = 0; listInd=-2; k++;
for (int i = 0; i < N; i++) break; j++;
for (int j = i; j < N; j++) }
}
}
if (isPermutation(A, B, N, i, j)) } void mergeSort(int arr[], int l, int r)
count = max(count, j - i + 1); cout<<listInd+1<<" "; {
cout << count << endl; }
} else{ if (l < r)
int main() cout<<listInd+1<<" "; {
{ } int mid = (l + r) / 2;
int T; } mergeSort(arr, l, mid);
cin >> T; } mergeSort(arr, mid + 1, r);
while (T--) } merge(arr, l, mid, r);
runTestCase(); }
}
return 0;
} int main()
{

int arr[] = {1, 2, 3, 4, 6, 5, 7, 8, 9, 10};

mergeSort(arr, 0, 9);
for (int i = 0; i < 10; i++)
{
cout << arr[i] << " ";
}
cout << endl;

return 0;
}

You might also like