Submission #36647519


Source Code Expand

#include<bits/stdc++.h>

using namespace std;
#define ll              long long
#define infi            INT_MAX
const long long mod = 1000000007;
#define spc             " "
#define nline            "\n"
#define pii             pair<int,int>
#define all(a)          a.begin(), a.end()
#define print(a)        cout << (a) << nline;
#define print2(a,b)      cout << (a) << " " << (b) << nline;
#define logarr(arr,a,b)    for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
#define printarr(arr,n) logarr(arr,0,n-1)
#define printmat(arr,r,c) for(int i=(0);i<(r);++i){logarr(arr[i],0,c-1)}
#define rep(i,_srt,_end)      for(int i=(_srt); i < (_end); ++i)


#ifndef ONLINE_JUDGE
    #define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#else
    #define bug(...) ;
#endif

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) {cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr (names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void file_i_o(){
    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);    
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif
}

//---------------------------Hello there----------------------------

const int N = 1e5 + 9;
vector<long long> t;
struct SegmentTree {

    int _n;
    static const long long inf = 1e18;

    SegmentTree() {
        //memset(t, 0, sizeof t);
    }

    void update(int in, int b, int e, int i, long long x) {
        if(b > i || e < i) return;
        if(b == e && b == i){
            t[in] = max(t[in], x);
            return;
        }
        int mid = (b + e) >> 1;
        update(2 * in, b, mid, i, x);
        update(2 * in + 1, mid + 1, e, i, x);
        t[in] = max(t[2 * in], t[2 * in + 1]);
    }

    void update(int i, long long x) {
        update(1, 0, _n, i, x);
    }

    long long query(int in, int b, int e, int l, int r){
        if(b > r || e < l) return 0;
        if(b >= l && e <= r) return t[in];
        int mid = (b + e) >> 1;
        long long L = query(2 * in, b, mid, l, r);
        long long R = query(2 * in + 1, mid + 1, e, l, r);
        return max(L, R);
    }

    long long query(int l, int r){        
        return query(1, 0, _n, l, r);
    }
};
SegmentTree tr;
void solve(){
    int n;
    cin >> n;
    tr._n = n;
    int a[n], b[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    t.resize(4 * n + 5);
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        int h = a[i];
        long long curr = tr.query(1, h - 1) + b[i];
        tr.update(h, curr);        
        ans = max(ans, curr);

    }
    cout << ans << nline;

}

int32_t main(int32_t argc, char const *argv[]){
    file_i_o();

    clock_t myclock = clock();

    solve();

    //cerr << "Run time: " << ((double)(clock() - myclock)/CLOCKS_PER_SEC) * 1000 << " ms" << endl;

    return 0;
}

Submission Info

Submission Time
Task Q - Flowers
User i_am_wiz
Language C++ (GCC 9.2.1)
Score 100
Code Size 3246 Byte
Status AC
Exec Time 121 ms
Memory 11136 KiB

Compile Error

./Main.cpp: In function ‘int32_t main(int32_t, const char**)’:
./Main.cpp:113:13: warning: unused variable ‘myclock’ [-Wunused-variable]
  113 |     clock_t myclock = clock();
      |             ^~~~~~~
./Main.cpp:110:22: warning: unused parameter ‘argc’ [-Wunused-parameter]
  110 | int32_t main(int32_t argc, char const *argv[]){
      |              ~~~~~~~~^~~~
./Main.cpp:110:40: warning: unused parameter ‘argv’ [-Wunused-parameter]
  110 | int32_t main(int32_t argc, char const *argv[]){
      |                            ~~~~~~~~~~~~^~~~~~

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 22
Set Name Test Cases
All 0_00, 0_01, 0_02, 0_03, 1_00, 1_01, 1_02, 1_03, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09, 1_10, 1_11, 1_12, 1_13, 1_14, 1_15, 1_16, 1_17
Case Name Status Exec Time Memory
0_00 AC 5 ms 3536 KiB
0_01 AC 2 ms 3576 KiB
0_02 AC 1 ms 3600 KiB
0_03 AC 2 ms 3536 KiB
1_00 AC 2 ms 3628 KiB
1_01 AC 100 ms 10980 KiB
1_02 AC 96 ms 11136 KiB
1_03 AC 94 ms 11000 KiB
1_04 AC 100 ms 11104 KiB
1_05 AC 96 ms 11088 KiB
1_06 AC 98 ms 11104 KiB
1_07 AC 101 ms 11032 KiB
1_08 AC 99 ms 11016 KiB
1_09 AC 102 ms 11032 KiB
1_10 AC 117 ms 11084 KiB
1_11 AC 119 ms 11016 KiB
1_12 AC 115 ms 11076 KiB
1_13 AC 119 ms 11072 KiB
1_14 AC 120 ms 11104 KiB
1_15 AC 120 ms 11100 KiB
1_16 AC 121 ms 11072 KiB
1_17 AC 119 ms 11048 KiB