답안 #280512

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
280512 2020-08-22T21:08:16 Z CaroLinda Rectangles (IOI19_rect) C++14
50 / 100
3288 ms 924712 KB
#include <bits/stdc++.h>
#include "rect.h"

#define sz(x) (int)x.size()
#define mkt make_tuple
#define lp(i,a,b) for(int i = a ; i < b ; i++ )
#define ff first
#define ss second
#define eb emplace_back
#define ll long long
#define mk make_pair
#define pii pair<int,int>
#define debug printf
#define all(x) x.begin(),x.end()

const int MAXN = 2510 ;

using namespace std ;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>

int N , M ;

void solve( vector< vector<int > > &grid, vector< vector< vector<pii> > > &toPut )
{

    int tamLinha = sz( grid[0] ) ;
    vector<int> esq(tamLinha) , dir(tamLinha) , getFreq( tamLinha ) , lastVisit(tamLinha) ;

    for(int i = 1 ; i < sz(grid) - 1 ; i++ )
    {

        for(int j = tamLinha - 1 ; j >= 0 ; j-- )
            esq[j] = dir[j] = -1 ;

        set<pii> s ;

        for(int j = tamLinha - 2;  j >= 0 ; j-- )
        {

            int x = j+1 ;

            while( x != -1 && grid[i][x]<= grid[i][j] )
                x = dir[x] ;

            dir[j] = x ;

        }

        for(int j = 1 ; j <  tamLinha ; j++ )
        {

            int x = j-1 ;

            while(x != -1 && grid[i][x] <= grid[i][j] )
                x = esq[x] ;

            esq[j] = x ;

        }

        lp(j,1,tamLinha-1)
            if( esq[j] != -1 && dir[j] != -1 && s.find(mk( esq[j] , dir[j] )) == s.end() )
            {
                toPut[ i ][ esq[j]+1 ].emplace_back( mk(dir[j]-1 , i) ) ;
                s.insert( mk(esq[j] , dir[j]) ) ;
            }

    }

   for(int j = 1 ; j < tamLinha ; j++ )
    {
        lp(i,0,tamLinha) getFreq[i] = lastVisit[i] = -1 ;

        for(int i = sz(grid) - 2 ; i >= 1 ; i-- )
            for(auto &e : toPut[i][j] )
            {
                if(  lastVisit[e.ff] != i+1 ) getFreq[e.ff] = i ;
                e.ss = getFreq[e.ff] ;
                lastVisit[e.ff] = i ;
            }
    }

}

ll count_rectangles( vector<vector<int> > mat )
{
    N = sz(mat) ;
    M = sz( mat[0] ) ;

    vector< vector<int> > gridCerto , gridRota ;
    vector< vector< vector<pii> > > auxCerto, auxRota ;
    lp(i,0,N)
    {
        gridCerto.emplace_back(*(new vector<int>)) ;
        auxCerto.emplace_back(*(new vector< vector<pii> >)) ;
        lp(j,0,M)
        {
            gridCerto[i].emplace_back( mat[i][j] ) ;
            auxCerto[i].emplace_back( *(new vector<pii>) ) ;
        }
    }
    lp(i,0,M)
    {
        gridRota.emplace_back( *(new vector<int>) ) ;
        auxRota.emplace_back(*(new vector< vector<pii> >)) ;
        lp(j,0,N)
        {
            gridRota[i].emplace_back( mat[j][i] ) ;
            auxRota[i].emplace_back( *(new vector<pii>) ) ;
        }
    }

    solve(gridCerto, auxCerto ) ;
    solve( gridRota, auxRota  );

   /* lp(i,1,N-1)
    {
        lp(j,1,M-1)
        {
            printf("Na casinha %d %d -> " , i , j ) ;
            for(auto e : auxCerto[i][j] ) printf("%d %d, " , e.ff, e.ss ) ;
            printf("\n") ;
        }
    } */

    ll ans = 0LL ;

    lp(i,1,N-1)
        lp(j,1,M-1)
        {
            sort( all(auxCerto[i][j]) ) ;
            sort( all(auxRota[j][i]) , [&](pii i, pii j) { return i.ss <= j.ss ; }) ;

            ordered_set o_set ;

            lp(e,0, sz(auxRota[j][i]) ) o_set.insert( mk(auxRota[j][i][e].ff, e) ) ;

            int ptr = 0 ;

            for(auto e : auxCerto[i][j] )
            {
                while( ptr < sz( auxRota[j][i] ) && auxRota[j][i][ptr].ss < e.ff )
                {
                    o_set.erase( o_set.find( mk(auxRota[j][i][ptr].ff, ptr) ) ) ;
                    ptr++ ;
                }

                ans += (ll)( o_set.order_of_key( mk( e.ss+1, -1 ) ) ) ;

            }


        }

    return ans ;

}


# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 5 ms 1792 KB Output is correct
18 Correct 5 ms 1792 KB Output is correct
19 Correct 5 ms 1792 KB Output is correct
20 Correct 4 ms 1556 KB Output is correct
21 Correct 6 ms 1536 KB Output is correct
22 Correct 6 ms 1536 KB Output is correct
23 Correct 6 ms 1536 KB Output is correct
24 Correct 3 ms 896 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 256 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 5 ms 1792 KB Output is correct
18 Correct 5 ms 1792 KB Output is correct
19 Correct 5 ms 1792 KB Output is correct
20 Correct 4 ms 1556 KB Output is correct
21 Correct 6 ms 1536 KB Output is correct
22 Correct 6 ms 1536 KB Output is correct
23 Correct 6 ms 1536 KB Output is correct
24 Correct 3 ms 896 KB Output is correct
25 Correct 36 ms 8568 KB Output is correct
26 Correct 30 ms 8544 KB Output is correct
27 Correct 36 ms 8568 KB Output is correct
28 Correct 24 ms 6912 KB Output is correct
29 Correct 36 ms 7424 KB Output is correct
30 Correct 43 ms 7544 KB Output is correct
31 Correct 34 ms 7416 KB Output is correct
32 Correct 33 ms 7288 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 0 ms 256 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 5 ms 1792 KB Output is correct
18 Correct 5 ms 1792 KB Output is correct
19 Correct 5 ms 1792 KB Output is correct
20 Correct 4 ms 1556 KB Output is correct
21 Correct 6 ms 1536 KB Output is correct
22 Correct 6 ms 1536 KB Output is correct
23 Correct 6 ms 1536 KB Output is correct
24 Correct 3 ms 896 KB Output is correct
25 Correct 36 ms 8568 KB Output is correct
26 Correct 30 ms 8544 KB Output is correct
27 Correct 36 ms 8568 KB Output is correct
28 Correct 24 ms 6912 KB Output is correct
29 Correct 36 ms 7424 KB Output is correct
30 Correct 43 ms 7544 KB Output is correct
31 Correct 34 ms 7416 KB Output is correct
32 Correct 33 ms 7288 KB Output is correct
33 Correct 269 ms 85112 KB Output is correct
34 Correct 257 ms 80248 KB Output is correct
35 Runtime error 1465 ms 162260 KB Execution killed with signal 11
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1920 KB Output is correct
2 Correct 8 ms 1664 KB Output is correct
3 Correct 9 ms 1664 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 10 ms 1920 KB Output is correct
6 Correct 10 ms 1920 KB Output is correct
7 Correct 11 ms 1920 KB Output is correct
8 Correct 10 ms 1920 KB Output is correct
9 Correct 10 ms 1920 KB Output is correct
10 Correct 9 ms 1024 KB Output is correct
11 Correct 9 ms 1408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1486 ms 432344 KB Output is correct
3 Correct 3288 ms 919840 KB Output is correct
4 Correct 3239 ms 924536 KB Output is correct
5 Correct 3255 ms 924712 KB Output is correct
6 Correct 898 ms 415844 KB Output is correct
7 Correct 1883 ms 775416 KB Output is correct
8 Correct 1963 ms 825208 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 5 ms 1792 KB Output is correct
18 Correct 5 ms 1792 KB Output is correct
19 Correct 5 ms 1792 KB Output is correct
20 Correct 4 ms 1556 KB Output is correct
21 Correct 6 ms 1536 KB Output is correct
22 Correct 6 ms 1536 KB Output is correct
23 Correct 6 ms 1536 KB Output is correct
24 Correct 3 ms 896 KB Output is correct
25 Correct 36 ms 8568 KB Output is correct
26 Correct 30 ms 8544 KB Output is correct
27 Correct 36 ms 8568 KB Output is correct
28 Correct 24 ms 6912 KB Output is correct
29 Correct 36 ms 7424 KB Output is correct
30 Correct 43 ms 7544 KB Output is correct
31 Correct 34 ms 7416 KB Output is correct
32 Correct 33 ms 7288 KB Output is correct
33 Correct 269 ms 85112 KB Output is correct
34 Correct 257 ms 80248 KB Output is correct
35 Runtime error 1465 ms 162260 KB Execution killed with signal 11
36 Halted 0 ms 0 KB -