Submission #88887


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
Task 15 - Empodia
User halilozanakgul
Language C++ (GCC 4.4.7)
Score 100
Code Size 1447 Byte
Status AC
Exec Time 789 ms
Memory 75044 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
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
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 139 ms 52688 KB
02 AC 155 ms 54736 KB
03 AC 147 ms 54736 KB
04 AC 152 ms 52676 KB
05 AC 135 ms 52592 KB
06 AC 132 ms 52664 KB
07 AC 130 ms 52580 KB
08 AC 165 ms 52684 KB
09 AC 137 ms 52540 KB
10 AC 129 ms 52548 KB
11 AC 162 ms 54752 KB
12 AC 204 ms 53816 KB
13 AC 161 ms 54080 KB
14 AC 164 ms 54080 KB
15 AC 163 ms 53456 KB
16 AC 158 ms 53564 KB
17 AC 160 ms 53692 KB
18 AC 516 ms 53248 KB
19 AC 679 ms 53560 KB
20 AC 789 ms 75044 KB