이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
//#define int long long
#define ll long long
typedef unsigned long long ull;
using namespace std;
const int N=1e5+5;
int n,m,q,w[N],W,seg[4*N+5],idx,val,lx,rx;
int build(int x,int l,int r){
if (l>r) return INT_MAX;
if (l==r) return seg[x]=w[l];
int mid=(l+r)/2;
return seg[x]=min(build(x*2,l,mid),build(x*2+1,mid+1,r));
}
void edit(int x,int l,int r){
if (l>r);
if (l==r){
seg[x]=val;
return;
}
int mid=(l+r)/2;
if (idx<=mid) edit(x*2,l,mid);
else edit(x*2+1,mid+1,r);
seg[x]=min(seg[x*2],seg[x*2+1]);
}
int query(int x,int l,int r){
if (l>=lx && r<=rx) return seg[x];
if (l>rx || r<lx || l>r) return INT_MAX;
int mid=(l+r)/2;
return min(query(x*2,l,mid),query(x*2+1,mid+1,r));
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n>>m;
for (int i=1;i<=m;i++){
int x,y;
cin>>x>>y>>w[i];
}
build(1,1,n-1);
cin>>q;
while (q--){
int t,x,y;
cin>>t>>x>>y;
if (t==1){
idx=x,val=y;
edit(1,1,n-1);
continue;
}
int ans=1,l=x,r=n-1,mid,z=x-1;
lx=x;
while (l<=r){
rx=mid=(l+r)/2;
int c=query(1,1,n-1);
if (c>=y){
z=mid;
l=mid+1;
}else r=mid-1;
}ans+=(z-x+1);
rx=x-1;
l=1,r=x-1,z=x;
while (l<=r){
lx=mid=(l+r)/2;
int c=query(1,1,n-1);
if (c>=y){
z=mid;
r=mid-1;
}else l=mid+1;
}ans+=x-z;
cout<<ans<<endl;
}
return 0;
}
# | 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... |