This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)
class ST{
lld arr[1200000];
public:
void build(int a, int b, int node){
if(a==b){
arr[node]=0;
return;
}
int mid=(a+b)/2;
build(a,mid,2*node);
build(mid+1,b,2*node+1);
arr[node]=min(arr[2*node],arr[2*node+1]);
}
void update(int a, int b, int node, int pos, lld val){
if(pos<a || b<pos)return;
if(a==b){
arr[node]=val;
return;
}
int mid=(a+b)/2;
update(a,mid,2*node,pos,val);
update(mid+1,b,2*node+1,pos,val);
arr[node]=min(arr[2*node],arr[2*node+1]);
}
lld query(int a, int b, int node, int x, int y){
if(b<x || y<a)return 1000000000000;
if(x<=a && b<=y)return arr[node];
int mid=(a+b)/2;
return min(query(a,mid,2*node,x,y),query(mid+1,b,2*node+1,x,y));
}
void print(int a, int b, int node){
cout<<a<<" "<<b<<" "<<arr[node]<<endl;
if(a==b)return;
int mid=(a+b)/2;
print(a,mid,2*node);
print(mid+1,b,2*node+1);
}
};
int main(){
int n,m,q;
cin>>n>>m;
lld edgelist[m][3];
rep(i,0,m){
rep(j,0,3){
cin>>edgelist[i][j];
if(j<2)edgelist[i][j]--;
}
}
cin>>q;
if(n<=1000 && m<=1000 && q<=10000){
while(q--){
int type;
cin>>type;
if(type==1){
int num;
lld val;
cin>>num>>val;
num--;
edgelist[num][2]=val;
}else{
int start;
lld w;
cin>>start>>w;
start--;
vector<int> nei[n];
bool visited[n];
rep(i,0,n)visited[i]=false;
//cout<<start<<endl;
rep(i,0,m){
if(edgelist[i][2]>=w){
//cout<<edgelist[i][0]<<" "<<edgelist[i][1]<<endl;
nei[edgelist[i][0]].push_back(edgelist[i][1]);
nei[edgelist[i][1]].push_back(edgelist[i][0]);
}
}
queue<int> q;
q.push(start);
visited[start]=true;
while(!q.empty()){
int u=q.front();q.pop();
trav(v,nei[u]){
if(!visited[v]){
visited[v]=true;
q.push(v);
}
}
}
lld ans=0;
rep(i,0,n)ans+=visited[i];
cout<<ans<<endl;
}
}
}
bool chain=(m==n-1);
rep(i,0,m){
if(edgelist[i][0]!=i || edgelist[i][1]!=i+1)chain=false;
}
if(chain){
ST *S=new ST();
S->build(0,n-2,1);
rep(i,0,n-1){
S->update(0,n-2,1,i,edgelist[i][2]);
}
while(q--){
int t;
cin>>t;
if(t==1){
int pos;
lld val;
cin>>pos>>val;
pos--;
S->update(0,n-2,1,pos,val);
}else{
int start;
lld weight;
cin>>start>>weight;
start--;
lld ans=0;
if(start>0){
int hi,lo;
hi=start;
lo=-1;
while(hi-lo>1){
int mid=(hi+lo)/2;
if(S->query(0,n-2,1,mid,start-1)<weight)lo=mid;
else hi=mid;
}
ans+=start-hi;
}
if(start<n-1){
int hi,lo;
hi=n-1;
lo=start-1;
while(hi-lo>1){
int mid=(hi+lo)/2;
if(S->query(0,n-2,1,start,mid)<weight)hi=mid;
else lo=mid;
}
ans+=lo-(start-1);
}
cout<<ans+1<<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... |