/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 332.0 KiB
#2 Accepted 180ms 740.0 KiB
#3 Accepted 187ms 908.0 KiB
#4 Accepted 187ms 928.0 KiB
#5 Accepted 213ms 2.469 MiB
#6 Accepted 283ms 2.461 MiB

Code

#include <bits/stdc++.h>
using namespace std;



const int INF = INT_MAX;
const int MAXN = 100005;
int tree[4 * MAXN]; 

int A[MAXN]; 

void build(int node, int start, int end) {
    if (start == end) {
        
        tree[node] = start;
    } else {
        int mid = (start + end) / 2;
        
        build(2 * node, start, mid);
        build(2 * node + 1, mid + 1, end);
        
        if (A[tree[2 * node]] <= A[tree[2 * node + 1]]) {
            tree[node] = tree[2 * node];
        } else {
            tree[node] = tree[2 * node + 1];
        }
    }
}

void update(int node, int start, int end, int idx, int value) {
    if (start == end) {
        
        A[idx] = value;
        tree[node] = start;
    } else {
        int mid = (start + end) / 2;
        if (start <= idx && idx <= mid) {
            
            update(2 * node, start, mid, idx, value);
        } else {
            
            update(2 * node + 1, mid + 1, end, idx, value);
        }
        
        if (A[tree[2 * node]] <= A[tree[2 * node + 1]]) {
            tree[node] = tree[2 * node];
        } else {
            tree[node] = tree[2 * node + 1];
        }
    }
}

int query(int node, int start, int end) {
    
    return tree[node];
}

int main() {
    int N, Q;

   
    cin >> N;

    
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }

   
    build(1, 0, N - 1);

    
    cin >> Q;

    while (Q--) {
        
        int min_pos = query(1, 0, N - 1);

      
        cout << (min_pos + 1) << endl;

        
        int X;
        cin >> X;

        
        update(1, 0, N - 1, min_pos, X);
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1086 KuZ the Position
Contest
Bangladesh 2.0
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-16 16:38:39
Judged At
2024-10-03 13:26:28
Judged By
Score
100
Total Time
283ms
Peak Memory
2.469 MiB