QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#575005 | #5512. Stone Arranging 2 | ModyKachef | 0 | 48ms | 10868kb | C++23 | 1.8kb | 2024-09-19 09:51:57 | 2024-09-19 09:51:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
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();
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 25
Accepted
time: 0ms
memory: 3516kb
input:
1 1
output:
1
result:
ok single line: '1 '
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 3632kb
input:
2 1 1
output:
1 1
result:
wrong answer 1st lines differ - expected: '1', found: '1 1 '
Subtask #2:
score: 0
Wrong Answer
Test #29:
score: 0
Wrong Answer
time: 48ms
memory: 10868kb
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:
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 1 1 1 ...
result:
wrong answer 1st lines differ - expected: '1', found: '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 '
Subtask #3:
score: 0
Skipped
Dependency #1:
0%