-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'AkashSingh3031:master' into rahul
- Loading branch information
Showing
5 changed files
with
320 additions
and
16 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
.... HackerEarth/1]. Practice/5]. Code Monk Series/1] Arrays & Strings/Monk and Rotation.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int T; | ||
cin>>T; | ||
while(T--) | ||
|
||
{ | ||
long long int n,k; | ||
cin>>n>>k; | ||
k=k%n; | ||
long long int a[n]; | ||
for(long long int i=0;i<n;i++) | ||
{ | ||
long long int data; | ||
cin>>a[i]; | ||
} | ||
for( int i=0;i<n;i++) | ||
{ | ||
cout<<a[((n-k+i)%n)]<<" "; | ||
} | ||
cout<<"\n";} | ||
} |
86 changes: 86 additions & 0 deletions
86
...05]. HackerEarth/1]. Practice/5]. Code Monk Series/1] Arrays & Strings/The Unlucky 13.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
#define int long long | ||
#define endl "\n" | ||
#define fastio() ios::sync_with_stdio(0);cin.tie(0) | ||
#define mod 1000000009 | ||
|
||
void io() | ||
{ | ||
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); | ||
#ifndef ONLINE_JUDGE | ||
freopen("/home/kashif/cp/input.txt","r",stdin); | ||
|
||
freopen("/home/kashif/cp/output.txt","w",stdout); | ||
#endif | ||
|
||
} | ||
int i,j,k; | ||
int M[4][4] = {{0,99,-10,2},{1,0,0,0},{0,1,0,0},{0,0,0,10}}; | ||
int p; | ||
void multiply(int a[4][4],int b[4][4]) | ||
{ | ||
|
||
int mul[4][4]={0}; | ||
for(i=0;i<4;i++) | ||
{ | ||
for(j=0;j<4;j++) | ||
{ | ||
for(k=0;k<4;k++) | ||
{ | ||
|
||
p=(a[i][k]*b[k][j]); | ||
mul[i][j]=(mul[i][j]+p); | ||
|
||
} | ||
} | ||
} | ||
|
||
|
||
for(i=0;i<4;i++) | ||
{ | ||
for(j=0;j<4;j++) | ||
a[i][j]=mul[i][j]%mod; | ||
} | ||
|
||
} | ||
void power(int a[4][4],int n) | ||
{ | ||
if(n==1 || n==0) | ||
return; | ||
power(a,n/2); | ||
multiply(a,a); | ||
if (n%2 != 0) | ||
multiply(a,M); | ||
} | ||
|
||
int32_t main() | ||
{ | ||
|
||
fastio(); | ||
io(); | ||
int t,n,ans; | ||
cin>>t; | ||
while(t--) | ||
{ | ||
|
||
cin>>n; | ||
if(n==0) | ||
printf("%d\n",1); | ||
else if(n==1) | ||
printf("%d\n",10); | ||
else if(n==2) | ||
printf("%d\n",99); | ||
else if(n==3) | ||
printf("%d\n",980); | ||
else | ||
{ | ||
int a[4][4]={{0,99,-10,2},{1,0,0,0},{0,1,0,0},{0,0,0,10}}; | ||
power(a,n-3); | ||
p=(a[3][3]*1000); | ||
k=(a[0][0]*20+a[0][1]+100*a[0][3])%mod; | ||
ans=(p-k+mod)%mod; | ||
printf("%lld\n",ans); | ||
} | ||
} | ||
} |
129 changes: 129 additions & 0 deletions
129
...rth/1]. Practice/5]. Code Monk Series/6]. Check Point - 1/Monk Celebrating Checkpoint.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#define _CRT_SECURE_NO_WARNINGS | ||
#include <fstream> | ||
#include <iostream> | ||
#include <string> | ||
#include <complex> | ||
#include <math.h> | ||
#include <set> | ||
#include <vector> | ||
#include <map> | ||
#include <queue> | ||
#include <stdio.h> | ||
#include <stack> | ||
#include <algorithm> | ||
#include <list> | ||
#include <ctime> | ||
|
||
#include <memory.h> | ||
#include <assert.h> | ||
|
||
#define y0 sdkfaslhagaklsldk | ||
|
||
#define y1 aasdfasdfasdf | ||
#define yn askfhwqriuperikldjk | ||
#define j1 assdgsdgasghsf | ||
#define tm sdfjahlfasfh | ||
#define lr asgasgash | ||
#define norm asdfasdgasdgsd | ||
#define have adsgagshdshfhds | ||
|
||
#define eps 1e-7 | ||
#define M_PI 3.141592653589793 | ||
#define bs 1000000007 | ||
#define bsize 337 | ||
|
||
using namespace std; | ||
|
||
const int INF = 1e9; | ||
const int N = 300031; | ||
|
||
int n, ar[N]; | ||
int k, x; | ||
vector<pair<int, int> > order; | ||
set<int> S; | ||
set<int>::iterator it; | ||
long long ANS; | ||
vector<pair<long long, long long> > T; | ||
long long C[N]; | ||
|
||
int main(){ | ||
//freopen("tree.in","r",stdin); | ||
//freopen("tree.out","w",stdout); | ||
// freopen("F:/input.txt", "r", stdin); | ||
// freopen("F:/output.txt", "w", stdout); | ||
ios_base::sync_with_stdio(0); | ||
//cin.tie(0); | ||
|
||
cin >> n >> x >> k; | ||
for (int i = 1; i <= n; i++) | ||
{ | ||
cin >> ar[i]; | ||
order.push_back(make_pair(ar[i], i)); | ||
} | ||
|
||
S.insert(0); | ||
S.insert(n+1); | ||
|
||
sort(order.begin(), order.end()); | ||
|
||
reverse(order.begin(), order.end()); | ||
|
||
for (int i = 0; i < order.size(); i++) | ||
{ | ||
int ps = order[i].second; | ||
it = S.lower_bound(ps); | ||
int val1 = (*it); | ||
--it; | ||
int val2 = (*it); | ||
// cout << val1 << " " << val2 << endl; | ||
|
||
long long here = (val1 - ps) * 1ll * (ps - val2 ); | ||
//cout << here << "%" << ar[ps] << endl; | ||
ANS += 1ll * here*ar[ps]; | ||
C[ps] = here; | ||
S.insert(ps); | ||
} | ||
//cout << ANS << endl; | ||
|
||
S.clear(); | ||
sort(order.begin(), order.end()); | ||
S.insert(0); | ||
S.insert(n + 1); | ||
|
||
for (int i = 0; i < order.size(); i++) | ||
{ | ||
int ps = order[i].second; | ||
it = S.lower_bound(ps); | ||
int val1 = (*it); | ||
--it; | ||
int val2 = (*it); | ||
// cout << val1 << " " << val2 << endl; | ||
|
||
long long here = (val1 - ps) * 1ll * (ps - val2); | ||
//cout << here << "%" << ar[ps] << endl; | ||
ANS -= 1ll * here*ar[ps]; | ||
//T.push_back(make_pair(here, ps)); | ||
C[ps] -= here; | ||
S.insert(ps); | ||
T.push_back(make_pair(C[ps], ps)); | ||
} | ||
|
||
/*for (int i = 1; i <= n; i++) | ||
{ | ||
cout << C[i] << " "; | ||
} | ||
cout << endl; | ||
*/ | ||
sort(T.begin(), T.end()); | ||
reverse(T.begin(), T.end()); | ||
|
||
for (int i = 0; i < x; i++) | ||
{ | ||
if (T[i].first>0) | ||
ANS += T[i].first; | ||
} | ||
cout << ANS << endl; | ||
|
||
cin.get(); cin.get(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters