이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define ii pair<int,int>
#define F first
#define S second
using namespace std;
const int N=1e5+100;
vector<int> g[N];
int seg[4*N];
void update(int p,int s,int e,int i,int v)
{
if(s==e){
seg[p]=v;
return;
}
int mid=(s+e)/2;
if(i<=mid){
update(p*2,s,mid,i,v);
}
else{
update(p*2+1,mid+1,e,i,v);
}
seg[p]=min(seg[p*2],seg[p*2+1]);
}
int get(int p,int s,int e,int a,int b)
{
if(a<=s&&e<=b){
return seg[p];
}
if(s>b||e<a)return 1e18;
int mid=(s+e)/2;
return min(get(p*2,s,mid,a,b),get(p*2+1,mid+1,e,a,b));
}
void solve()
{
int n,m;
cin>>n>>m;
for(int i=1;i<n;i++){
int b;
scanf("%lld",&b);
scanf("%lld",&b);
scanf("%lld",&b);
update(1,1,n,i,b);
}
int q;
cin>>q;
while(q--){
int t;
scanf("%lld",&t);
if(t==1){
int b,w;
scanf("%lld",&b);
scanf("%lld",&w);
update(1,1,n,b,w);
}
else{
int b,w;
scanf("%lld",&b);
scanf("%lld",&w);
int ans=1;
if(b!=1){
int l=1,r=b-1,ann=b;
while(l<=r){
int mid=(l+r)/2;
if(get(1,1,n,mid,b-1)>=w){
ann=mid;
r=mid-1;
}
else{
l=mid+1;
}
}
ans+=b-ann;
}
if(b!=n){
int l=b,r=n-1,ann=b;
while(l<=r){
int mid=(l+r)/2;
if(get(1,1,n,b,mid)>=w){
ann=mid+1;
l=mid+1;
}
else{
r=mid-1;
}
}
ans+=ann-b;
}
printf("%lld\n",ans);
}
}
}
main()
{
int t=1;
// cin>>t;
while(t--){
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
bridges.cpp:95:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
95 | main()
| ^~~~
bridges.cpp: In function 'void solve()':
bridges.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%lld",&b);
| ~~~~~^~~~~~~~~~~
bridges.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | scanf("%lld",&b);
| ~~~~~^~~~~~~~~~~
bridges.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%lld",&b);
| ~~~~~^~~~~~~~~~~
bridges.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | scanf("%lld",&t);
| ~~~~~^~~~~~~~~~~
bridges.cpp:54:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
54 | scanf("%lld",&b);
| ~~~~~^~~~~~~~~~~
bridges.cpp:55:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
55 | scanf("%lld",&w);
| ~~~~~^~~~~~~~~~~
bridges.cpp:60:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | scanf("%lld",&b);
| ~~~~~^~~~~~~~~~~
bridges.cpp:61:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | scanf("%lld",&w);
| ~~~~~^~~~~~~~~~~
# | 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... |