提出 #12899490


ソースコード 拡げる

#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 make_pair(inf, 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, K, D, A[201010];
SegTree<pair<int, int>, 1 << 18> st;
int ans[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> K >> D;
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, N) st.update(i, make_pair(A[i], i));

    int idx = 0;
    rep(k, 0, K) {
        int rest = K - k;

        // [L, R]
        int L = idx;
        int R = N - 1 - ((rest - 1) * D);

        if (R < L) {
            cout << -1 << endl;
            return;
        }
        
        auto p = st.get(L, R + 1);
        ans[k] = p.first;
        idx = p.second + D;
    }

    rep(i, 0, K) {
        if(i) printf(" ");
        printf("%d", ans[i]);
    }
    printf("\n");
}





提出情報

提出日時
問題 L - 辞書順最小
ユーザ hamayanhamayan
言語 C++ (GCC 9.2.1)
得点 6
コード長 2791 Byte
結果 AC
実行時間 77 ms
メモリ 8756 KiB

コンパイルエラー

./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];
      |                                          ^~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 6 / 6
結果
AC × 4
AC × 41
セット名 テストケース
Sample s1.txt, s2.txt, s3.txt, s4.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, s1.txt, s2.txt, s3.txt, s4.txt
ケース名 結果 実行時間 メモリ
01.txt AC 40 ms 8168 KiB
02.txt AC 30 ms 7904 KiB
03.txt AC 18 ms 7704 KiB
04.txt AC 17 ms 7260 KiB
05.txt AC 23 ms 7640 KiB
06.txt AC 39 ms 8076 KiB
07.txt AC 27 ms 7796 KiB
08.txt AC 19 ms 7656 KiB
09.txt AC 6 ms 7164 KiB
10.txt AC 25 ms 7900 KiB
11.txt AC 32 ms 8168 KiB
12.txt AC 26 ms 7528 KiB
13.txt AC 31 ms 8196 KiB
14.txt AC 32 ms 8064 KiB
15.txt AC 7 ms 7132 KiB
16.txt AC 5 ms 7220 KiB
17.txt AC 9 ms 7256 KiB
18.txt AC 12 ms 7216 KiB
19.txt AC 28 ms 7668 KiB
20.txt AC 57 ms 8440 KiB
21.txt AC 49 ms 8328 KiB
22.txt AC 61 ms 8692 KiB
23.txt AC 33 ms 8168 KiB
24.txt AC 32 ms 8084 KiB
25.txt AC 33 ms 7792 KiB
26.txt AC 23 ms 7488 KiB
27.txt AC 59 ms 8756 KiB
28.txt AC 32 ms 8220 KiB
29.txt AC 52 ms 8320 KiB
30.txt AC 32 ms 8064 KiB
31.txt AC 68 ms 8612 KiB
32.txt AC 71 ms 8604 KiB
33.txt AC 66 ms 8640 KiB
34.txt AC 56 ms 8444 KiB
35.txt AC 35 ms 8232 KiB
36.txt AC 77 ms 8660 KiB
37.txt AC 30 ms 8200 KiB
s1.txt AC 7 ms 7284 KiB
s2.txt AC 6 ms 7220 KiB
s3.txt AC 7 ms 7220 KiB
s4.txt AC 5 ms 7148 KiB