QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#575004#5512. Stone Arranging 2ModyKachef0 53ms5952kbC++231.8kb2024-09-19 09:51:192024-09-19 09:51:21

Judging History

你现在查看的是最新测评结果

  • [2024-09-19 09:51:21]
  • 评测
  • 测评结果:0
  • 用时:53ms
  • 内存:5952kb
  • [2024-09-19 09:51:19]
  • 提交

answer

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

struct SegmentTree{
    vector<int> seg;
    int m;
    void init(int n){
        m = 1<<(__lg(n-1)+1);
        seg.resize(2*m , 1e18);
    }
    void propagate(int s , int e,  int p){
        if (s == e) return;
        if (seg[p] != 1e18){
            seg[2*p] = seg[2*p+1] = seg[p];
            seg[p] = 1e18;
        }
    }
    void update(int l , int r , int v , int s , int e , int p){
        propagate(s , e , p);
        if (l > e || r < s) return;
        else if (l <= s && r >= e) {
            seg[p] = v;
            return;
        } 
        update(l , r , v , s , (s+e)/2 , 2*p);
        update(l , r , v , (s+e)/2 + 1 , e , 2*p+1);
    }
    int get(int id , int s , int e , int p){
        propagate(s , e , p); 
        if (s == e) return seg[p];
        if (id <= (s+e)/2) return get(id , s , (s+e)/2 , 2*p);
        else return get(id , (s+e)/2 +1 , e , 2*p+1); 
    }
    void update(int l , int r , int v){
        update(l , r , v ,1 , m , 1);
    }
    int get(int id){
        return get(id , 1 , m , 1); 
    }
};

SegmentTree st; 

void doWork(){
    int n;
    cin >> n;
    st.init(n); 
    map<int , vector<int>> mp; 
    int a[n+1] = {};
    for (int i = 1 ; i <= n ; i++){
        cin >> a[i];
    }
    for (int i = 1 ; i <= n ; i++){
        int l = i;  
        while(!mp[a[i]].empty()){
            if (st.get(mp[a[i]].back()) == a[i]) {l = mp[a[i]].back(); break;}
            else mp[a[i]].pop_back(); 
        }
        st.update(l , i , a[i]); 
        mp[a[i]].push_back(i); 
    }
    for (int i = 1 ; i <= n ; i++){
        cout << st.get(i) << ' '; 
    }
}   

signed main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    doWork();
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 25
Accepted
time: 0ms
memory: 3576kb

input:

1
1

output:

1 

result:

ok single line: '1 '

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 3876kb

input:

2
1
1

output:

2147483647 2147483647 

result:

wrong answer 1st lines differ - expected: '1', found: '2147483647 2147483647 '

Subtask #2:

score: 0
Wrong Answer

Test #29:

score: 0
Wrong Answer
time: 53ms
memory: 5952kb

input:

200000
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1...

output:

2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 214...

result:

wrong answer 1st lines differ - expected: '1', found: '2147483647 2147483647 21474836...47483647 2147483647 2147483647 '

Subtask #3:

score: 0
Skipped

Dependency #1:

0%