이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define MAXN 400100
int n,m,q, l[MAXN], r[MAXN], v[MAXN];
void build(int i, int rl, int rr) {
l[i] = rl, r[i] = rr;
if(rl!=rr)
build(i*2,rl,rl+rr>>1),
build(i*2+1,rl+rr+2>>1,rr);
}
void upd(int i, int p, int x) {
if(l[i]==r[i]) return (void)(v[i]=x);
if(p>r[i*2])
upd(i*2+1,p,x);
else upd(i*2,p,x);
v[i]=min(v[i*2],v[i*2+1]);
}
int query(int i, int rl, int rr){
if(rl>r[i]||l[i]>rr) return 2e9;
if(rl<=l[i]&&r[i]<=rr) return v[i];
return min(query(i*2,rl,rr),query(i*2+1,rl,rr));
}
signed main() {
cin >> n >> m;
build(1,1,m);
for(int i = 1; i <= m; i++) {
int a;
cin >> a >> a >> a;
upd(1,i,a);
}
cin >> n;
while(n--) {
int a,b,c;
cin>>a>>c>>b;
if(a-1){
int l = 1, r = b, lpos;
while(l<r) {
int mid = l+r>>1;
if(query(1,mid,b-1) >= c)
r = mid;
else
l = mid+1;
}
lpos = l;
l = b, r = m;
while(l<r){
int mid = l+r+2>>1;
if(query(1, b, mid-1) >= c)
l = mid;
else
r = mid-1;
}
cout << r-lpos+1 << '\n';
} else upd(1,c,b);
}
}
컴파일 시 표준 에러 (stderr) 메시지
bridges.cpp: In function 'void build(int, int, int)':
bridges.cpp:8:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
8 | build(i*2,rl,rl+rr>>1),
| ~~^~~
bridges.cpp:9:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
9 | build(i*2+1,rl+rr+2>>1,rr);
| ~~~~~^~
bridges.cpp: In function 'int main()':
bridges.cpp:38:28: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
38 | int mid = l+r>>1;
| ~^~
bridges.cpp:47:30: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
47 | int mid = l+r+2>>1;
| ~~~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |