Submission #88486


Source Code Expand

/*  
Alfonso2 Peterssen  
9 - 5 - 2008  
IOI 2004 Day2 Task "Empodia"  
*/   
#include <cstdio>   
#include <algorithm>   
#include <stack>   
   
using namespace std;   
   
const int MAXN = 1100000;   
   
typedef pair< int, int > par;   
   
int N, E, cant;   
int i, j, a, b;   
int seq[MAXN];   
int ans[MAXN];   
int last[MAXN];   
int next[MAXN];   
int empodio[MAXN];   
bool deleted[MAXN];   
stack< int > S;   
par vals[MAXN];   
par events[MAXN];   
   
int main() {   
   
    scanf( "%d", &N );   
    for ( i = 0; i < N; i++ )   
        scanf( "%d", &seq[i] );   
   
    for ( i = 0; i < N; last[i] = j, i++ )   
        for ( j = i - 1; j >= 0 && seq[j] < seq[i]; j = last[j] );   
   
    for ( i = N - 1; i >= 0; next[i] = j, i-- )   
        for ( j = i + 1; j < N && seq[j] > seq[i]; j = next[j] );   
   
    for ( i = 0; i < N; i++ )   
        vals[i] = par( seq[i] - i, i );   
   
    /* Find all empodios */   
    sort( vals, vals + N );   
    for ( i = 0; i < N; i++ ) {   
        a = vals[i].second;   
        for ( j = i + 1; j < N &&   
              vals[i].first == vals[j].first; j++ ) {   
            b = vals[j].second;   
            if ( next[a] <= b ) break;   
            if ( last[b] < a && next[a] > b ) {   
                empodio[b] = a;   
                events[E++] = par( a, +(i+1) );   
                events[E++] = par( b, -(i+1) );   
                break;   
            }   
        }   
    }   
   
    /* Find inner intervals */   
    sort( events, events + E );   
    for ( i = 0; i < E; i++ ) {   
        int id = events[i].second;   
        if ( id > 0 ) S.push( abs(id) );   
        if ( id < 0 && !deleted[ abs(id) ] ) {   
            while ( !S.empty() ) {   
                deleted[ S.top() ] = true;   
                S.pop();   
            }   
            ans[cant++] = events[i].first;   
        }   
    }   
   
    printf( "%d\n", cant );   
    for ( i = 0; i < cant; i++ )   
        printf( "%d %d\n", empodio[ ans[i] ] + 1, ans[i] + 1 );   
   
    return 0;   
}   

Submission Info

Submission Time
Task 15 - Empodia
User oyildiz
Language C++ (G++ 4.6.4)
Score 100
Code Size 2139 Byte
Status AC
Exec Time 583 ms
Memory 35032 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:31:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:33:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-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 125 ms 17884 KB
02 AC 51 ms 18052 KB
03 AC 50 ms 17940 KB
04 AC 49 ms 17908 KB
05 AC 52 ms 18056 KB
06 AC 49 ms 17976 KB
07 AC 50 ms 18008 KB
08 AC 51 ms 17984 KB
09 AC 51 ms 17952 KB
10 AC 55 ms 18060 KB
11 AC 85 ms 18524 KB
12 AC 69 ms 18732 KB
13 AC 67 ms 18720 KB
14 AC 70 ms 18716 KB
15 AC 70 ms 18852 KB
16 AC 70 ms 18720 KB
17 AC 72 ms 18844 KB
18 AC 103 ms 18376 KB
19 AC 117 ms 18648 KB
20 AC 583 ms 35032 KB