Submission #88884
Source Code Expand
#include<iostream>
#include<algorithm>
#include<fstream>
#include<cstring>
#include<stack>
#include<vector>
using namespace std;
#define f first
#define s second
#define mp make_pair
#define T 1100000
int di[1100005],nkeb[1100005],nkek[1100005];
int n;
vector < int > v[2200005];
vector < pair < int , int > > qq,ww;
void oku(){
int i;
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d",&di[i]);
}
stack < pair < int , int > > st;
void coz(){
int i,j,k;
for(i=1;i<=n;i++){
while(!st.empty() && st.top().f>di[i]){
nkek[st.top().s]=i-1;
st.pop();
}
st.push(mp(di[i],i));
}
while(!st.empty()){
nkek[st.top().s]=n;
st.pop();
}
for(i=n;i>=1;i--){
while(!st.empty() && st.top().f<di[i]){
nkeb[st.top().s]=i+1;
st.pop();
}
st.push(mp(di[i],i));
}
while(!st.empty()){
nkeb[st.top().s]=1;
st.pop();
}
for(i=1;i<=n;i++)
v[di[i]-i+T].push_back(i);
int a,b;
for(k=0;k<=2200000;k++)
for(i=0;i<v[k].size();i++)
for(j=i+1;j<v[k].size();j++){
a=v[k][i];
b=v[k][j];
if(nkeb[b]<=a && nkek[a]>=b)
qq.push_back(mp(a,b));
}
sort(qq.begin(),qq.end());
int mn=1000000000;
for(i=qq.size()-1;i>=0;i--){
if(mn>qq[i].s)
ww.push_back(qq[i]);
mn=min(mn,qq[i].s);
}
sort(ww.begin(),ww.end());
cout<<ww.size()<<endl;
for(i=0;i<ww.size();i++)
cout<<ww[i].f<<" "<<ww[i].s<<endl;
}
int main(){
oku();
coz();
return 0;
}
Submission Info
Submission Time
2013-07-07 15:06:42+0900
Task
15 - Empodia
User
halilozanakgul
Language
C++ (GCC 4.4.7)
Score
100
Code Size
1447 Byte
Status
AC
Exec Time
840 ms
Memory
75052 KB
Compile Error
./Main.cpp: In function ‘void oku()’:
./Main.cpp:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
./Main.cpp:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
Judge Result
Set Name
Set01
Set02
Set03
Set04
Set05
Set06
Set07
Set08
Set09
Set10
Set11
Set12
Set13
Set14
Set15
Set16
Set17
Set18
Set19
Set20
Score / Max Score
5 / 5
5 / 5
5 / 5
5 / 5
5 / 5
5 / 5
5 / 5
5 / 5
5 / 5
5 / 5
5 / 5
5 / 5
5 / 5
5 / 5
5 / 5
5 / 5
5 / 5
5 / 5
5 / 5
5 / 5
Status
Set Name
Test Cases
Set01
01
Set02
02
Set03
03
Set04
04
Set05
05
Set06
06
Set07
07
Set08
08
Set09
09
Set10
10
Set11
11
Set12
12
Set13
13
Set14
14
Set15
15
Set16
16
Set17
17
Set18
18
Set19
19
Set20
20
Case Name
Status
Exec Time
Memory
01
AC
151 ms
52684 KB
02
AC
157 ms
54720 KB
03
AC
158 ms
54700 KB
04
AC
129 ms
52540 KB
05
AC
127 ms
52572 KB
06
AC
129 ms
52664 KB
07
AC
137 ms
52536 KB
08
AC
143 ms
52636 KB
09
AC
129 ms
52540 KB
10
AC
139 ms
52584 KB
11
AC
153 ms
54712 KB
12
AC
181 ms
53840 KB
13
AC
161 ms
54076 KB
14
AC
158 ms
54092 KB
15
AC
164 ms
53432 KB
16
AC
160 ms
53560 KB
17
AC
154 ms
53708 KB
18
AC
513 ms
53208 KB
19
AC
677 ms
53564 KB
20
AC
840 ms
75052 KB