| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 75344 | FiloSanza | Deda (COCI17_deda) | C++14 | 594 ms | 3700 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct segmentTree{
const int nullval = 2e9;
int S;
vector<int> v;
segmentTree(int s){
S = (1<<((int)ceil(log2(s))+1)) - 1;
v.resize(S, nullval);
}
inline int father(int pos){ return (pos-1)/2; }
inline int left(int pos){ return (pos*2)+1; }
inline int right(int pos){ return (pos+1)*2; }
void update(int pos, int val){
pos = pos + S/2;
assert(v[pos] == nullval);
v[pos] = val;
while(pos != 0){
pos = father(pos);
v[pos] = min(v[left(pos)], v[right(pos)]);
}
}
int solve(int pos, int val){
while(pos < S/2){
if(v[left(pos)] <= val)
pos = left(pos);
else
pos = right(pos);
}
return pos - S/2;
}
int _query(int pos, int a, int b, int l, int val){
if(b < l)
return nullval;
if(v[pos] > val)
return nullval;
if(a >= l)
return solve(pos, val);
int mid = (a + b)/2;
return min(_query(left(pos), a, mid, l, val), _query(right(pos), mid+1, b, l, val));
}
int query(int pos, int val){
int ans = _query(0, 0, S/2, pos, val);
if(ans == nullval) return -1;
else return ans;
}
void debug(){
cout << "\n\n\nDEBUG\n\n\n";
for(auto i : v) cout << i << " ";
cout << "\n\n\nDEBUG\n\n\n";
}
};
int main(){
int N, Q;
cin >> N >> Q;
char c;
int a, b;
segmentTree tree(N);
while(Q--){
cin >> c >> a >> b;
b--;
if(c == 'M'){
tree.update(b, a);
}
else{
int ans = tree.query(b, a);
cout << (ans == -1 ? -1 : ans+1) << "\n";
}
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
