Submission #14068492


Source Code Expand

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
#define def inf
template<class V, int NV> struct SegTree { //[l,r)
    V comp(V& l, V& r) { return min(l, r); };

    vector<V> val; SegTree() { val = vector<V>(NV * 2, def); }
    V get(int x, int y, int l = 0, int r = NV, int k = 1) {
        if (r <= x || y <= l)return def; if (x <= l && r <= y)return val[k];
        auto a = get(x, y, l, (l + r) / 2, k * 2);
        auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
        return comp(a, b);
    }
    void update(int i, V v) {
        i += NV; val[i] = v;
        while (i > 1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
    }
    void add(int i, V v) { update(i, val[i + NV] + v); }
    V operator[](int x) { return get(x, x + 1); }
};
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, M, A[301010];
SegTree<int, 1 << 17> st;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M;
    rep(i, 0, M) cin >> A[i];

    rep(i, 0, N) st.update(i, 0);
    rep(i, 0, M) {
        int ng = 0, ok = N + 1;
        while (ng + 1 != ok) {
            int md = (ng + ok) / 2;
            if (st.get(0, md) < A[i]) ok = md;
            else ng = md;
        }
        if (ok != N + 1) {
            int eat = ok - 1;
            st.update(eat, A[i]);
            printf("%d\n", eat + 1);
        }
        else printf("-1\n");
    }
}





Submission Info

Submission Time
Task J - Sushi-go-round
User hamayanhamayan
Language C++ (GCC 9.2.1)
Score 6
Code Size 2654 Byte
Status AC
Exec Time 370 ms
Memory 5600 KiB

Compile Error

./Main.cpp: In member function ‘V SegTree<V, NV>::get(int, int, int, int, int)’:
./Main.cpp:18:9: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
   18 |         if (r <= x || y <= l)return def; if (x <= l && r <= y)return val[k];
      |         ^~
./Main.cpp:18:42: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
   18 |         if (r <= x || y <= l)return def; if (x <= l && r <= y)return val[k];
      |                                          ^~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 6 / 6
Status
AC × 3
AC × 19
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, max_01.txt, max_02.txt, max_03.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
hand_01.txt AC 272 ms 5276 KiB
hand_02.txt AC 301 ms 5140 KiB
hand_03.txt AC 323 ms 5284 KiB
hand_04.txt AC 370 ms 5264 KiB
hand_05.txt AC 369 ms 5104 KiB
max_01.txt AC 325 ms 5144 KiB
max_02.txt AC 327 ms 5600 KiB
max_03.txt AC 325 ms 5296 KiB
random_01.txt AC 34 ms 4936 KiB
random_02.txt AC 6 ms 3992 KiB
random_03.txt AC 268 ms 5268 KiB
random_04.txt AC 35 ms 4000 KiB
random_05.txt AC 228 ms 5056 KiB
random_06.txt AC 208 ms 4992 KiB
random_07.txt AC 279 ms 5140 KiB
random_08.txt AC 204 ms 4952 KiB
sample_01.txt AC 3 ms 4092 KiB
sample_02.txt AC 3 ms 4028 KiB
sample_03.txt AC 3 ms 3996 KiB