/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 94ms 6.727 MiB
#3 Accepted 104ms 7.113 MiB
#4 Accepted 105ms 7.086 MiB
#5 Accepted 141ms 14.68 MiB
#6 Accepted 145ms 14.566 MiB

Code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> PII;
const ll mx = 3e5+10;

int arr[mx];
int tree[mx * 3];
void init(int node, int b, int e) {
    if(b == e) {
        tree[node] = arr[b];
        return;
    }
    int Left = node * 2;
    int Right = node * 2 + 1;
    int mid = (b + e) / 2;
    init(Left, b, mid);
    init(Right, mid + 1, e);
    tree[node] = min(tree[Left], tree[Right]);
}
int query(int node, int b, int e, int i, int j) {
    if(i > e || j < b)
        return 1e18;
    if(b >= i && e <= j)
        return tree[node];
    int Left = node * 2;
    int Right = node * 2 + 1;
    int mid = (b + e) / 2;
    int p1 = query(Left, b, mid, i, j);
    int p2 = query(Right, mid + 1, e, i, j);
    return min(p1, p2);
}
void update(int node, int b, int e, int i, int newvalue) {
    if(i > e || i < b)
        return;
    if(b >= i && e <= i) {
        tree[node] = newvalue;
        return;
    }
    int Left = node * 2;
    int Right = node * 2 + 1;
    int mid = (b + e) / 2;
    update(Left, b, mid, i, newvalue);
    update(Right, mid + 1, e, i, newvalue);
    tree[node] = min(tree[Left], tree[Right]);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin>> n;

    map<ll,ll> Mp;
    for(int i=1;i<=n;i++) {
        cin >> arr[i];
        Mp[arr[i]] = i;
    }
    init(1,1,n);

    int q;
    cin >> q;

    while(q--) {
        ll num;
        cin >> num;
        ll Ans = query(1,1,n, 1, n);
        cout<<Mp[Ans]<<"\n";
        update(1,1,n, Mp[Ans], num);
        Mp[num] = Mp[Ans];
    }
}



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 15:48:02
Judged At
2024-10-03 13:29:50
Judged By
Score
100
Total Time
145ms
Peak Memory
14.68 MiB