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 4a4d407

Browse files
Initial commit
1 parent 1e20c02 commit 4a4d407

File tree

6 files changed

+202
-1
lines changed

6 files changed

+202
-1
lines changed

‎.vscode/settings.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"files.associations": {
3-
"iostream": "cpp"
3+
"iostream": "cpp",
4+
"ostream": "cpp"
45
}
56
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//author @Nishant
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
const int mod = 1e9 + 7;
6+
7+
int main(){
8+
int n, k;
9+
cin >> n >> k;
10+
stack<pair<int, int>> s;
11+
int val;
12+
long long ans = 1;
13+
for(int i = 0; i < n; i++){
14+
cin >> val;
15+
while(!s.empty() && s.top().first > val){
16+
ans = (ans * (i - s.top().second + 1)) % mod;
17+
s.pop();
18+
}
19+
s.push({val, i});
20+
}
21+
cout << ans << endl;
22+
return 0;
23+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//author @Nishant
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
6+
int prec(char c) {
7+
if(c == '^') return 3;
8+
else if(c == '*' || c == '/') return 2;
9+
else if(c == '+' || c == '-') return 1;
10+
else return -1;
11+
}
12+
13+
int main(){
14+
int t;
15+
cin >> t;
16+
while(t--){
17+
int n;
18+
cin >> n;
19+
string s;
20+
cin >> s;
21+
22+
stack<char> opr;
23+
string ans = "";
24+
25+
for(int i = 0; i < n; i++){
26+
if((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z')){
27+
ans += s[i];
28+
}else if(s[i] == '('){
29+
opr.push('(');
30+
}else if(s[i] == ')'){
31+
while(!opr.empty() && opr.top() != '('){
32+
char c = opr.top();
33+
opr.pop();
34+
ans += c;
35+
}
36+
if(opr.top() == '('){
37+
opr.pop();
38+
}
39+
}else{
40+
while(!opr.empty() && prec(s[i]) <= prec(opr.top())){
41+
char c = opr.top();
42+
opr.pop();
43+
ans += c;
44+
}
45+
opr.push(s[i]);
46+
}
47+
}
48+
while(!opr.empty()) {
49+
char c = opr.top();
50+
opr.pop();
51+
ans += c;
52+
}
53+
cout << ans << endl;
54+
}
55+
return 0;
56+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//author @Nishant
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
6+
int main(){
7+
int t;
8+
cin >> t;
9+
while(t--){
10+
int n, k;
11+
cin >> n >> k;
12+
vector<int> a(n);
13+
vector<int> s(k, 0);
14+
for(int i = 0; i < n; i++){
15+
cin >> a[i];
16+
}
17+
18+
int ans = 0;
19+
for(int i = 0; i < n; i++){
20+
int count = i - s[a[i] - 1];
21+
s[a[i] - 1] = i + 1;
22+
ans = max(count, ans);
23+
}
24+
25+
for(int i = 0; i < k; i++){
26+
ans = max(ans, n - s[i]);
27+
}
28+
29+
cout << ans << endl;
30+
31+
}
32+
return 0;
33+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//author @Nishant
2+
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
#define MAX 1000002
6+
7+
int main(){
8+
int n, x, y, t1, t2, duration = INT_MAX;
9+
cin >> n >> x >> y;
10+
int in[MAX], out[MAX];
11+
vector<pair<int, int>> contest;
12+
memset(in, -1, sizeof(int) * MAX);
13+
memset(out, -1, sizeof(int) * MAX);
14+
for (int i = 0; i < n; i++){
15+
cin >> t1 >> t2;
16+
contest.push_back(make_pair(t1, t2));
17+
}
18+
for (int i = 0; i < x; i++){
19+
cin >> t1;
20+
in[t1] = t1;
21+
}
22+
for (int i = 0; i < y; i++){
23+
cin >> t1;
24+
out[t1] = t1;
25+
}
26+
t1 = -1;
27+
for (int i = 1; i < MAX; i++){
28+
if (in[i] != -1)
29+
t1 = in[i];
30+
else
31+
in[i] = t1;
32+
}
33+
t1 = -1;
34+
for (int i = MAX - 1; i > 0; i--){
35+
if (out[i] != -1)
36+
t1 = out[i];
37+
else
38+
out[i] = t1;
39+
}
40+
for (auto i = contest.begin(); i != contest.end(); i++){
41+
if (in[i->first] != -1 && out[i->second] != -1 && (out[i->second] - in[i->first] + 1 < duration))
42+
duration = out[i->second] - in[i->first] + 1;
43+
}
44+
cout << duration << endl;
45+
return 0;
46+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//author @Nishant
2+
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
int main()
7+
{
8+
int n, maxAr = 0;
9+
cin >> n;
10+
vector<int> a(100001, 500);
11+
for (int i = 0; i < n; i++){
12+
int x, y;
13+
cin >> x >> y;
14+
a[x] = min(a[x], y);
15+
}
16+
stack<int> st;
17+
vector<int> right(100001, 100000), left(100001, 0);
18+
for (int i = 1; i < 100001; i++){
19+
while (!st.empty() && a[i] <= a[st.top()])
20+
{
21+
st.pop();
22+
}
23+
left[i] = st.size() ? st.top() : 0;
24+
st.push(i);
25+
}
26+
st = stack<int>();
27+
for (int i = 100000; i >= 0; i--){
28+
while (!st.empty() && a[i] <= a[st.top()])
29+
{
30+
st.pop();
31+
}
32+
right[i] = st.size() ? st.top() : 100000;
33+
st.push(i);
34+
}
35+
for (int i = 0; i <= 100000; i++){
36+
maxAr = max(maxAr, a[i] * (right[i] - left[i]));
37+
}
38+
39+
cout << maxAr << endl;
40+
41+
return 0;
42+
}

0 commit comments

Comments
(0)

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