이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> >v[100005];
int w[100005];
int vis[100005];
struct segtree{
int info[400005];
void upd(int st,int en,int i,int pos,int val){
if(st>pos||en<pos)return;
if(st==en)return void(info[i]=val);
int m=(st+en)/2;
upd(st,m,i*2,pos,val);
upd(m+1,en,i*2+1,pos,val);
info[i]=max(info[i*2],info[i*2+1]);
}
int fmax(int st,int en,int i,int l,int r){
if(st>r||en<l)return 0;
if(st>=l&&en<=r)return info[i];
int m=(st+en)/2;
return max(fmax(st,m,i*2,l,r),fmax(m+1,en,i*2+1,l,r));
}
}tr;
/*int dfs(int x,int wc){
vis[x]=1;
int sz=1;
for(auto e:v[x]){
if(w[e.second]>=wc&&vis[e.first]==0){
sz+=dfs(e.first,wc);
}
}
return sz;
}*/
int main(){
int n,m;
cin>>n>>m;
for(int i=1;i<=m;i++){
int a,b,c;
cin>>a>>b>>c;
tr.upd(1,n,1,i,c);
}
int q;
cin>>q;
while(q--){
int t;
cin>>t;
if(t==1){
int x,r;
cin>>x>>r;
tr.upd(1,n,1,x,r);
}else{
int s,w;
cin>>s>>w;
//cout<<dfs(s,w)<<"\n";
int rans=1;
int st,en,ans;
st=1,en=s-1,ans=s;
while(st<=en){
int m=(st+en)/2;
if(tr.fmax(1,n,1,s-1,m)<=w){
ans=m;
en=m-1;
}else{
st=m+1;
}
}
rans+=s-ans;
st=s,en=n-1,ans=s-1;
while(st<=en){
int m=(st+en)/2;
if(tr.fmax(1,n,1,s,m)<=w){
ans=m;
st=m+1;
}else{
en=m-1;
}
}
rans+=ans+1-s;
cout<<rans<<"\n";
}
}
}
# | 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... |