Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7b90b29

Browse files
Added more cool stuff
1 parent e562f97 commit 7b90b29

File tree

3 files changed

+248
-0
lines changed

3 files changed

+248
-0
lines changed

‎DPandbitmasking/Countingstrings.cpp‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
3+
Name: Mehul Chaturvedi
4+
IIT-Guwahati
5+
6+
*/
7+
8+
/*
9+
PROBLEM STATEMENT
10+
Given a string 's' consisting of upper case alphabets, i.e. from 'A' to 'Z'. Your task is to find how many strings 't' with length equal to that of 's', also consisting of upper case alphabets are there satisfying the following conditions:
11+
-> String 't' is lexicographical larger than string 's'.
12+
-> When you write both 's' and 't' in the reverse order, 't' is still lexicographical larger than 's'.
13+
Find out number of such strings 't'. As the answer could be very large, take modulo 10^9 + 7.
14+
*/
15+
16+
#include <bits/stdc++.h>
17+
using namespace std;
18+
19+
typedef long long ll;
20+
typedef unordered_map<int, int> umapii;
21+
typedef unordered_map<int, bool> umapib;
22+
typedef unordered_map<string, int> umapsi;
23+
typedef unordered_map<string, string> umapss;
24+
typedef map<string, int> mapsi;
25+
typedef map<pair<int, int>, int> mappiii;
26+
typedef map<int, int> mapii;
27+
typedef pair<int, int> pii;
28+
typedef pair<long long, long long> pll;
29+
typedef unordered_set<int> useti;
30+
31+
#define uset unordered_set
32+
#define it iterator
33+
#define mp make_pair
34+
#define pb push_back
35+
#define all(x) (x).begin(), (x).end()
36+
#define f first
37+
#define s second
38+
#define MOD 1000000007
39+
40+
#include<bits/stdc++.h>
41+
using namespace std;
42+
long long ans[100001],mod=1e9+7;
43+
int go(string s){
44+
string str="";
45+
int n=s.length();
46+
for(int i=n-1;i>=1;i--)
47+
str.push_back(s.at(i));
48+
for(int i=0;i<n-1;i++)
49+
ans[i]=(ans[i-1]*26%mod+90-str.at(i))%mod;
50+
long long a=0;
51+
ans[-1]=0;
52+
for(int i=0;i<n;i++)
53+
{
54+
a=(a+(90-s.at(i))*(ans[n-i-2]+1)%mod)%mod;
55+
}
56+
return a;
57+
}
58+
59+
int countStrings(char* s) {
60+
int i=0;
61+
string s1="";
62+
while(s[i]!='0円'){
63+
s1=s1+s[i];
64+
i++;
65+
}
66+
67+
return go(s1);
68+
}
69+
70+
int main( int argc , char ** argv )
71+
{
72+
ios_base::sync_with_stdio(false) ;
73+
cin.tie(NULL) ;
74+
75+
char s[100005];
76+
cin>>s;
77+
int ans = countStrings(s);
78+
cout<<ans<<endl;
79+
80+
81+
return 0 ;
82+
83+
84+
85+
}

‎Tries/Test.txt‎

Whitespace-only changes.

‎Tries/maximumxorsub.cpp‎

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/*
2+
3+
Name: Mehul Chaturvedi
4+
IIT-Guwahati
5+
6+
*/
7+
8+
/*
9+
PROBLEM STATEMENT
10+
Given an array of n integers, find subarray whose xor is maximum.
11+
Input Format
12+
First line contains single integer n (1<=n<=1000000).
13+
Next line contains n space separated integers.
14+
Output Format
15+
Print xor of the subarray whose xor of all elements in subarray is maximum over all subarrays.
16+
Constraints
17+
1 <= n <= 1000000
18+
1 <= A[i] <=100000
19+
Sample Input
20+
4
21+
1 2 3 4
22+
Sample Output
23+
7
24+
*/
25+
26+
#include <bits/stdc++.h>
27+
using namespace std;
28+
29+
typedef long long ll;
30+
typedef unordered_map<int, int> umapii;
31+
typedef unordered_map<int, bool> umapib;
32+
typedef unordered_map<string, int> umapsi;
33+
typedef unordered_map<string, string> umapss;
34+
typedef map<string, int> mapsi;
35+
typedef map<pair<int, int>, int> mappiii;
36+
typedef map<int, int> mapii;
37+
typedef pair<int, int> pii;
38+
typedef pair<long long, long long> pll;
39+
typedef unordered_set<int> useti;
40+
41+
#define uset unordered_set
42+
#define it iterator
43+
#define mp make_pair
44+
#define pb push_back
45+
#define all(x) (x).begin(), (x).end()
46+
#define f first
47+
#define s second
48+
#define MOD 1000000007
49+
50+
#include<bits/stdc++.h>
51+
using namespace std;
52+
53+
// Assumed int size
54+
#define INT_SIZE 32
55+
56+
// A Trie Node
57+
struct TrieNode
58+
{
59+
int value; // Only used in leaf nodes
60+
TrieNode *arr[2];
61+
};
62+
63+
// Utility function tp create a Trie node
64+
TrieNode *newNode()
65+
{
66+
TrieNode *temp = new TrieNode;
67+
temp->value = 0;
68+
temp->arr[0] = temp->arr[1] = NULL;
69+
return temp;
70+
}
71+
72+
// Inserts pre_xor to trie with given root
73+
void insert(TrieNode *root, int pre_xor)
74+
{
75+
TrieNode *temp = root;
76+
77+
// Start from the msb, insert all bits of
78+
// pre_xor into Trie
79+
for (int i=INT_SIZE-1; i>=0; i--)
80+
{
81+
// Find current bit in given prefix
82+
bool val = pre_xor & (1<<i);
83+
84+
// Create a new node if needed
85+
if (temp->arr[val] == NULL)
86+
temp->arr[val] = newNode();
87+
88+
temp = temp->arr[val];
89+
}
90+
91+
// Store value at leaf node
92+
temp->value = pre_xor;
93+
}
94+
95+
// Finds the maximum XOR ending with last number in
96+
// prefix XOR 'pre_xor' and returns the XOR of this maximum
97+
// with pre_xor which is maximum XOR ending with last element
98+
// of pre_xor.
99+
int query(TrieNode *root, int pre_xor)
100+
{
101+
TrieNode *temp = root;
102+
for (int i=INT_SIZE-1; i>=0; i--)
103+
{
104+
// Find current bit in given prefix
105+
bool val = pre_xor & (1<<i);
106+
107+
// Traverse Trie, first look for a
108+
// prefix that has opposite bit
109+
if (temp->arr[1-val]!=NULL)
110+
temp = temp->arr[1-val];
111+
112+
// If there is no prefix with opposite
113+
// bit, then look for same bit.
114+
else if (temp->arr[val] != NULL)
115+
temp = temp->arr[val];
116+
}
117+
return pre_xor^(temp->value);
118+
}
119+
120+
// Returns maximum XOR value of a subarray in arr[0..n-1]
121+
int maxSubarrayXOR(int arr*, int n)
122+
{
123+
// Create a Trie and insert 0 into it
124+
TrieNode *root = newNode();
125+
insert(root, 0);
126+
127+
// Initialize answer and xor of current prefix
128+
int result = INT_MIN, pre_xor =0;
129+
130+
// Traverse all input array element
131+
for (int i=0; i<n; i++)
132+
{
133+
// update current prefix xor and insert it into Trie
134+
pre_xor = pre_xor^arr[i];
135+
insert(root, pre_xor);
136+
137+
// Query for current prefix xor in Trie and update
138+
// result if required
139+
result = max(result, query(root, pre_xor));
140+
}
141+
return result;
142+
}
143+
144+
int main( int argc , char ** argv )
145+
{
146+
ios_base::sync_with_stdio(false) ;
147+
cin.tie(NULL) ;
148+
149+
int n;
150+
cin>>n;
151+
int* arr = new int[n];
152+
for (int i = 0; i < n; ++i)
153+
{
154+
cin>>arr[i];
155+
}
156+
157+
cout << maxSubarrayXOR(arr, n) << '\n';
158+
159+
return 0 ;
160+
161+
162+
163+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /