forked from ds-sww/codebase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
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,43 @@ | ||
#include<iostream> | ||
#include<stack> | ||
#include<algorithm> | ||
using namespace std; | ||
int func(const int* a,const int count){ | ||
stack<int> r; | ||
int temp; | ||
int minium=0; | ||
int s=0; | ||
int w = 0; | ||
for (int i=0; i < count;i++){ | ||
if (r.size()==0||a[i] >= a[r.top()]){ | ||
r.push(i); | ||
} | ||
else{ | ||
while (!r.empty() && a[r.top()] > a[i]){ | ||
temp = r.top(); | ||
r.pop(); | ||
w = r.empty() ? i : (i - r.top()-1); | ||
s = max(s, a[temp] * w); | ||
} | ||
r.push(i); | ||
} | ||
} | ||
return s; | ||
} | ||
int main(){ | ||
int count; | ||
int flag = 0; | ||
cin >> count; | ||
while (count){ | ||
int *a = new int[count+1]; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
for (int i = 0; i < count; i++) | ||
cin >> a[i]; | ||
a[count] = 0; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
if (flag) | ||
cout << endl; | ||
cout << func(a,count+1); | ||
flag = 1; | ||
cin >> count; | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include<iostream> | ||
#include <stack> | ||
#include<string> | ||
using namespace std; | ||
string t=""; | ||
void func(const int* a,const int count){ | ||
stack<int> p; | ||
int j = 1; | ||
int i = 0; | ||
int flag = 0; | ||
for (; i < count;){ | ||
if (a[i] > j) | ||
p.push(j++); | ||
else if(a[i]==j){ | ||
j++; | ||
i++; | ||
} | ||
else{ | ||
if (a[i] == p.top()){ | ||
i++; | ||
p.pop(); | ||
} | ||
else{ | ||
flag = 0; | ||
break; | ||
} | ||
} | ||
if (j == count + 1 && i == count){ | ||
t+= "\nYes"; | ||
flag = 1; | ||
break; | ||
} | ||
} | ||
if (!flag) | ||
t += "\nNo"; | ||
|
||
} | ||
int main(){ | ||
int count,temp,flag=1; | ||
cin >> count; | ||
for (; count;cin>>count){ | ||
int *a = new int[count]; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
//cout << endl;//Blank line? | ||
while (1){ | ||
cin >> temp; | ||
if (temp == 0){ | ||
t += "\n"; | ||
break; | ||
} | ||
This comment has been minimized.
Sorry, something went wrong. |
||
else{ | ||
a[0] = temp; | ||
for (int i = 1; i < count; i++) | ||
cin >> a[i]; | ||
func(a,count); | ||
} | ||
} | ||
} | ||
cout << t.substr(1,t.length()-2); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include<iostream> | ||
using namespace std; | ||
int a[1000005],q[1000005]; | ||
void minq(int n,int m){ | ||
int tail = 0, head = 1; | ||
for (int i = 1; i <= n; i++){ | ||
while (head <= tail&&a[q[tail]] >= a[i]) tail--; | ||
q[++tail] = i; | ||
if (i >= m){ | ||
while (q[head]<i - m + 1) head++; | ||
cout<<a[q[head]]<<" "; | ||
} | ||
} | ||
cout << endl; | ||
} | ||
void maxq(int n,int m){ | ||
int tail = 0, head = 1; | ||
for (int i = 1; i <= n; i++){ | ||
while (head <= tail&&a[q[tail]] <= a[i]) tail--; | ||
q[++tail] = i; | ||
if (i >= m){ | ||
while (q[head]<i - m + 1) head++; | ||
cout<<a[q[head]]<<" "; | ||
} | ||
} | ||
} | ||
int main() | ||
{ | ||
int n, k; | ||
cin >> n >> k; | ||
for (int i = 1; i <= n; i++){ | ||
cin >> a[i]; | ||
} | ||
This comment has been minimized.
Sorry, something went wrong. |
||
minq(n, k); | ||
maxq(n, k); | ||
return 0; | ||
} |
释放空间