Submission #88885


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 856 ms
Memory 75048 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 132 ms 52668 KB
02 AC 151 ms 54784 KB
03 AC 182 ms 54720 KB
04 AC 134 ms 52540 KB
05 AC 151 ms 52576 KB
06 AC 126 ms 52664 KB
07 AC 184 ms 52556 KB
08 AC 152 ms 52672 KB
09 AC 140 ms 52544 KB
10 AC 125 ms 52540 KB
11 AC 155 ms 54732 KB
12 AC 177 ms 53836 KB
13 AC 153 ms 54124 KB
14 AC 167 ms 54108 KB
15 AC 157 ms 53436 KB
16 AC 159 ms 53564 KB
17 AC 158 ms 53692 KB
18 AC 518 ms 53176 KB
19 AC 660 ms 53584 KB
20 AC 856 ms 75048 KB