Submission #250576

# Submission time Handle Problem Language Result Execution time Memory
250576 2020-07-18T12:13:24 Z CaroLinda Selling RNA Strands (JOI16_selling_rna) C++14
100 / 100
969 ms 136708 KB
#include <bits/stdc++.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 pb push_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 MAX = 4e5+10 ;

using namespace std ;

struct Seg
{
    vector<int> t[MAX*4] ;

    int m(int l, int r) { return (l+r)>>1 ; }

    void upd(int pos, int l, int r, int idx, int val )
    {
        t[pos].pb(val) ;
        if(l == r) return ;
        if(idx <= m(l,r)) upd(pos<<1 ,l, m(l,r) , idx, val ) ;
        else upd(pos<<1|1,m(l,r)+1, r, idx, val) ;
    }

    void build(int pos, int l, int r)
    {
        sort(all(t[pos])) ;

        if(l==r) return ;

        build(pos<<1 , l, m(l,r) ) ;
        build(pos<<1|1,m(l,r)+1 , r );
    }

    int qry(int pos, int l, int r , int beg, int en, int val1, int val2)
    {
        if( l > en || r < beg ) return 0 ;
        if( l >= beg && r <= en ) return lower_bound( all(t[pos]) , val2 ) - lower_bound( all(t[pos]) , val1 ) ;

        int al = qry(pos<<1 , l, m(l,r) , beg, en , val1, val2 ) ;
        int ar = qry(pos<<1|1 , m(l,r) + 1 , r , beg, en ,val1, val2 ) ;

        return al + ar ;

    }

} seg ;

int N , M , T, curr ;
int id[MAX][2] ;
int tam[MAX][2] ;
char aux[MAX] ;
vector<char> str[MAX][2] ;

int get(char c)
{
    if(c == 'A') return 0 ;
    if( c == 'C' ) return 1 ;
    if( c == 'G' ) return 2 ;
    if(c == 'U') return 3 ;
    return 4 ;
}

inline void process(int idx, int bit, vector<int> v )
{

    vector<int> vv[5] ;

    sort( all(v) , [&](int i, int j){return i > j ;} ) ;

    for(auto e : v )
    {
        if( bit > tam[e][idx]-1 )
            id[e][idx] = ++curr ;
        else vv[ get(str[e][idx][bit]) ].pb(e) ;
    }

    for(int i = 0 ; i < 5 ; i++ )
        if(vv[i].size() > 0)
            process(idx, bit+1, vv[i]) ;

}

int main()
{
    //Input ----------------------------------------
    scanf("%d%d", &N , &M ) ; T = N+M ;
    lp(i,1,N+1)
    {
        scanf("%s", aux) ;
        tam[i][0] = tam[i][1] = strlen(aux) ;

        lp(j,0,tam[i][0]) str[i][0].pb(aux[j]) ;
        for(int j = tam[i][0]-1 ; j >= 0 ; j-- ) str[i][1].pb( aux[j] ) ;
    }
    lp(i,N+1,T+1)
        lp(j,0,2)
        {
            scanf("%s", aux ) ;
            tam[i][j] = strlen(aux) ;
            lp(g,0,tam[i][j]) str[i][j].pb( aux[g] ) ;
        }

    lp(i,N+1,T+1)
    {
        str[i+T][0] = str[i][0] ;
        str[i+T][0].pb('Z') ;
        tam[i+T][0] = tam[i][0] + 1 ;

        reverse( all(str[i][1]) ) ;

        str[i+T][1] = str[i][1] ;
        str[i+T][1].pb( 'Z' ) ;
        tam[i+T][1] = tam[i][1] + 1 ;

    }
    //----------------------------------------------

    vector<int> v(T) ;
    iota(all(v),1) ;

    lp(i,N+1,T+1) v.pb(i+T) ;

    lp(i,0,2)
    {
        curr =0 ;
        process(i,0,v) ;
    }

    lp(i,1,N+1) seg.upd(1,1,2*T,id[i][0], id[i][1]) ;
    seg.build(1,1,2*T) ;

    lp(i,N+1,T+1) printf("%d\n", seg.qry(1,1,2*T, id[i][0] , id[i+T][0] , id[i][1] , id[i+T][1] ) ) ;

}

Compilation message

selling_rna.cpp: In function 'int main()':
selling_rna.cpp:96:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N , &M ) ; T = N+M ;
     ~~~~~^~~~~~~~~~~~~~~~~~
selling_rna.cpp:99:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s", aux) ;
         ~~~~~^~~~~~~~~~~
selling_rna.cpp:108:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%s", aux ) ;
             ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 36 ms 56700 KB Output is correct
2 Correct 36 ms 56704 KB Output is correct
3 Correct 37 ms 56696 KB Output is correct
4 Correct 32 ms 56704 KB Output is correct
5 Correct 37 ms 56696 KB Output is correct
6 Correct 32 ms 56704 KB Output is correct
7 Correct 32 ms 56704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 517 ms 123996 KB Output is correct
2 Correct 536 ms 121080 KB Output is correct
3 Correct 539 ms 121932 KB Output is correct
4 Correct 524 ms 120960 KB Output is correct
5 Correct 535 ms 66132 KB Output is correct
6 Correct 534 ms 65872 KB Output is correct
7 Correct 458 ms 122744 KB Output is correct
8 Correct 606 ms 92044 KB Output is correct
9 Correct 582 ms 97144 KB Output is correct
10 Correct 404 ms 88000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 210 ms 76080 KB Output is correct
2 Correct 164 ms 68168 KB Output is correct
3 Correct 182 ms 72580 KB Output is correct
4 Correct 155 ms 69920 KB Output is correct
5 Correct 161 ms 68156 KB Output is correct
6 Correct 187 ms 72620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 56700 KB Output is correct
2 Correct 36 ms 56704 KB Output is correct
3 Correct 37 ms 56696 KB Output is correct
4 Correct 32 ms 56704 KB Output is correct
5 Correct 37 ms 56696 KB Output is correct
6 Correct 32 ms 56704 KB Output is correct
7 Correct 32 ms 56704 KB Output is correct
8 Correct 517 ms 123996 KB Output is correct
9 Correct 536 ms 121080 KB Output is correct
10 Correct 539 ms 121932 KB Output is correct
11 Correct 524 ms 120960 KB Output is correct
12 Correct 535 ms 66132 KB Output is correct
13 Correct 534 ms 65872 KB Output is correct
14 Correct 458 ms 122744 KB Output is correct
15 Correct 606 ms 92044 KB Output is correct
16 Correct 582 ms 97144 KB Output is correct
17 Correct 404 ms 88000 KB Output is correct
18 Correct 210 ms 76080 KB Output is correct
19 Correct 164 ms 68168 KB Output is correct
20 Correct 182 ms 72580 KB Output is correct
21 Correct 155 ms 69920 KB Output is correct
22 Correct 161 ms 68156 KB Output is correct
23 Correct 187 ms 72620 KB Output is correct
24 Correct 608 ms 121356 KB Output is correct
25 Correct 710 ms 125652 KB Output is correct
26 Correct 568 ms 120056 KB Output is correct
27 Correct 618 ms 121632 KB Output is correct
28 Correct 969 ms 136708 KB Output is correct
29 Correct 818 ms 99388 KB Output is correct