/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 1ms 536.0 KiB
#5 Accepted 1ms 532.0 KiB
#6 Accepted 1ms 332.0 KiB
#7 Accepted 1ms 536.0 KiB
#8 Accepted 1ms 464.0 KiB
#9 Accepted 1ms 500.0 KiB
#10 Accepted 1ms 536.0 KiB
#11 Accepted 1ms 532.0 KiB
#12 Accepted 1ms 532.0 KiB
#13 Accepted 1ms 524.0 KiB
#14 Accepted 1ms 548.0 KiB
#15 Accepted 1ms 356.0 KiB
#16 Accepted 1ms 532.0 KiB
#17 Accepted 1ms 480.0 KiB
#18 Accepted 1ms 532.0 KiB
#19 Accepted 1ms 532.0 KiB
#20 Accepted 1ms 484.0 KiB
#21 Accepted 1ms 352.0 KiB
#22 Accepted 1ms 420.0 KiB
#23 Accepted 1ms 532.0 KiB
#24 Accepted 1ms 484.0 KiB
#25 Accepted 1ms 356.0 KiB
#26 Accepted 1ms 532.0 KiB
#27 Accepted 1ms 520.0 KiB
#28 Accepted 1ms 416.0 KiB
#29 Accepted 1ms 532.0 KiB
#30 Accepted 1ms 532.0 KiB
#31 Accepted 1ms 488.0 KiB
#32 Accepted 1ms 328.0 KiB
#33 Accepted 1ms 488.0 KiB
#34 Accepted 1ms 320.0 KiB
#35 Accepted 1ms 532.0 KiB
#36 Accepted 1ms 448.0 KiB
#37 Accepted 1ms 484.0 KiB
#38 Accepted 1ms 532.0 KiB
#39 Accepted 1ms 532.0 KiB
#40 Accepted 1ms 532.0 KiB
#41 Accepted 2ms 532.0 KiB
#42 Accepted 1ms 532.0 KiB
#43 Accepted 2ms 532.0 KiB
#44 Accepted 2ms 580.0 KiB
#45 Accepted 2ms 600.0 KiB
#46 Accepted 2ms 544.0 KiB
#47 Accepted 2ms 532.0 KiB
#48 Accepted 2ms 532.0 KiB
#49 Accepted 2ms 344.0 KiB
#50 Accepted 2ms 532.0 KiB
#51 Accepted 2ms 524.0 KiB
#52 Accepted 1ms 320.0 KiB
#53 Accepted 2ms 532.0 KiB
#54 Accepted 2ms 532.0 KiB
#55 Accepted 2ms 532.0 KiB
#56 Accepted 4ms 532.0 KiB
#57 Accepted 4ms 532.0 KiB
#58 Accepted 4ms 532.0 KiB
#59 Accepted 5ms 532.0 KiB
#60 Accepted 5ms 532.0 KiB
#61 Accepted 15ms 800.0 KiB
#62 Accepted 8ms 580.0 KiB
#63 Accepted 10ms 532.0 KiB
#64 Accepted 12ms 564.0 KiB
#65 Accepted 12ms 548.0 KiB
#66 Accepted 10ms 532.0 KiB
#67 Accepted 10ms 532.0 KiB
#68 Accepted 10ms 532.0 KiB
#69 Accepted 10ms 632.0 KiB
#70 Accepted 10ms 532.0 KiB
#71 Accepted 24ms 788.0 KiB
#72 Accepted 8ms 532.0 KiB
#73 Accepted 11ms 584.0 KiB
#74 Accepted 16ms 580.0 KiB
#75 Accepted 16ms 788.0 KiB
#76 Accepted 13ms 504.0 KiB
#77 Accepted 12ms 704.0 KiB
#78 Accepted 13ms 648.0 KiB
#79 Accepted 9ms 532.0 KiB
#80 Accepted 10ms 532.0 KiB
#81 Accepted 24ms 836.0 KiB
#82 Accepted 6ms 532.0 KiB
#83 Accepted 8ms 604.0 KiB
#84 Accepted 10ms 788.0 KiB
#85 Accepted 22ms 1020.0 KiB
#86 Accepted 17ms 584.0 KiB
#87 Accepted 16ms 536.0 KiB
#88 Accepted 17ms 664.0 KiB
#89 Accepted 16ms 580.0 KiB
#90 Accepted 16ms 688.0 KiB
#91 Accepted 94ms 2.184 MiB
#92 Accepted 28ms 1.16 MiB
#93 Accepted 40ms 1.336 MiB
#94 Accepted 49ms 3.914 MiB
#95 Accepted 47ms 4.027 MiB
#96 Accepted 36ms 1.359 MiB
#97 Accepted 35ms 1.41 MiB
#98 Accepted 37ms 1.273 MiB
#99 Accepted 38ms 1.312 MiB
#100 Accepted 35ms 1.273 MiB

Code

// I AM A MUSLIM

#include "bits/stdc++.h"

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#define fast_io std::ios::sync_with_stdio(0);std::cin.tie(0)
#define lli long long int
#define flush fflush(stdout)
#define line printf("\n")
#define yn(a, b) printf("%s\n", (a) >= (b) ? "Yes":"No")
#define amodm(a, M) (((a)%M+M)%M)
#define read(s) std::string s;std::cin >> s
#define readL(s) std::string s;getline(std::cin, s)
#define write(s) printf("%s\n", s.c_str())
// #define int lli

using pii = std::pair<int,int>;
const int MOD = 1000000007;
const int mxN = 500100;

int left[4 * mxN], right[4 * mxN];

void upd_left(int at, int l, int r, int idx) {
    if (idx < l || idx >= r) return;
    if (l+1 == r) {
        left[at] += 1;
        return;
    }
    int m = l + (r - l) / 2;
    upd_left(2 * at + 1, l, m, idx);
    upd_left(2 * at + 2, m, r, idx);
    left[at] = left[2 * at + 1] + left[2 * at + 2];
}

void upd_right(int at, int l, int r, int idx) {
    if (idx < l || idx >= r) return;
    if (l+1 == r) {
        right[at] += 1;
        return;
    }
    int m = l + (r - l) / 2;
    upd_right(2 * at + 1, l, m, idx);
    upd_right(2 * at + 2, m, r, idx);
    right[at] = right[2 * at + 1] + right[2 * at + 2];
}

int que_left(int at, int l, int r, int L, int R) {
    if (r <= L || R <= l) return 0;
    if (L <= l && r <= R) return left[at];
    if (l + 1 == r) return 0;
    int m = l + (r - l) / 2;
    return que_left(2 * at + 1, l, m, L, R) + que_left(2 * at + 2, m, r, L, R);
}

int que_right(int at, int l, int r, int L, int R) {
    if (r <= L || R <= l) return 0;
    if (L <= l && r <= R) return right[at];
    if (l + 1 == r) return 0;
    int m = l + (r - l) / 2;
    return que_right(2 * at + 1, l, m, L, R) + que_right(2 * at + 2, m, r, L, R);
}

signed main() {
    int testCases=1;
    // scanf("%d",&testCases);
    
    for (int TC = 1; TC <= testCases; TC++) {
        int n;
        scanf("%d",&n);
        int a[n];
        for (int i = 0; i < n; i++) {
            scanf("%d",&a[i]);
        }
        int ans[n]={0};
        for (int i = 0; i < n; i++) {
            int v = a[i];
            int val = que_left(0, 0, 3*n, 0, v+1);
            upd_left(0, 0, 3*n, v);
            if (val >= v) ans[i]++;
        }
        for (int i = n-1; i >= 0; i--) {
            int v = a[i];
            int val = que_right(0, 0, 3*n, 0, v);
            val = (n-i-1) - val;
            upd_right(0, 0, 3*n, v);
            if (val >= v) ans[i]++;
        }
        int fin = 0;
        for (int i = 0; i < n; i++) {
            if (ans[i]) fin++;
            // printf("%d ", ans[i]);
        }
        printf("%d\n", fin);
    }
    
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1184 The Curious Kid and the Number Game
Contest
Brain Booster #9
Language
C++17 (G++ 13.2.0)
Submit At
2025-04-06 16:18:01
Judged At
2025-04-06 16:18:01
Judged By
Score
100
Total Time
94ms
Peak Memory
4.027 MiB