#include <bits/stdc++.h>
using namespace std;
#define sonic ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define IO(main) if(fopen(main".inp","r")){freopen(main".inp","r",stdin);freopen(main".out","w",stdout);}
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define ins insert
#define pb push_back
#define el cout << endl
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define MASK(i) ((1LL)<<(i))
#define BIT(x,i) (((x)>>(i))&(1LL))
#define FOR(i, a, b) for(int (i)=(a);(i)<=(b); i++)
#define FORD(i, a, b) for(int (i)=(a);(i)>=(b); i--)
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<pii>;
const int N = 1e6 + 9;
const int mod = 1e9 + 7;
const ll INF = 1e18 + 7;
const int base = 31;
const int LOG = 20;
const ll MOD = 1e9 + 7;
int mul(int x, int y) {return 1LL * x * y % mod;}
int calPw(int x, int y)
{
int ans = 1;
while(y)
{
if (y&1) ans = 1LL * ans * x % mod;
x = 1LL * x * x % mod;
y >>= 1;
}
return ans;
}
int d4x[4] = {1, 0, -1, 0};
int d4y[4] = {0, 1, 0, -1};
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
///Author: Le Chi Thien Luong The Vinh high school 2008
///code
template<class X, class Y>
bool minimize(X &x , Y y){
if(x > y){
x = y;
return true;
}
return false;
}
template<class X, class Y>
bool maximize(X &x , Y y){
if(x < y){
x = y;
return true;
}
return false;
}
template<class X, class Y>
bool add(X &x , Y y){
if((x + y ) >= mod){
ll tmp = x + y;
x = tmp - mod;
return true;
}
return false;
}
void Solve(){
}
int n, m, q;
struct Edge{
int u, v, w;
}e[N];
int lab[N];
int Find(int u){
if(lab[u] < 0)return u;
lab[u] = Find(lab[u]);
return lab[u];
}
bool dsu(int u, int v){
u = Find(u);
v = Find(v);
if(u == v)return false;
if(lab[u] > lab[v])swap(u, v);
lab[u] += lab[v];
lab[v] = u;
return true;
}
struct ST{
int st[4 * N + 2];
void update(int u, int val, int id = 1, int l =1, int r =n){
if(l == r){
st[id] = val;
return;
}
int mid = l + r >> 1;
if(u <= mid)update(u, val, id * 2, l, mid);
else update(u, val, id * 2 + 1, mid + 1, r);
st[id] = min(st[id * 2], st[id * 2 + 1]);
}
int get(int u, int v, int id =1 , int l = 1, int r = n){
if(v < l || r < u)return 1e9;
if(l >= u && r <= v)return st[id];
int mid = l + r >> 1;
int A = get(u, v, id * 2, l, mid);
int B = get(u, v, id * 2 + 1, mid + 1, r);
return min(A, B);
}
}it;
void Read(){
cin >> n >> m ;
FOR(i, 1, m){
int u, v, w;
cin >> u >> v >> w;
e[i] = {u, v, w};
}
cin >> q;
// if(n <= 1000 && q <= 10000 && m <= 1000){
// FOR(j, 1, q){
// int t, u, v;
// cin >> t >> u >> v;
// if(t == 1){
// e[u].w = v;
// }
// else{
// FOR(i, 1, n)lab[i] = -1;
// FOR(i, 1, m){
// if(e[i].w >= v)dsu(e[i].u, e[i].v);
// }
// cout << -lab[Find(u)] << endl;
// }
// }return;
// }
FOR(i, 1, m){
it.update(i, e[i].w);
}
FOR(j, 1, q){
int t, u, v;
cin >> t >> u >> v;
if(t == 1)it.update(u, v);
else{
int ans = 0;
int l = 1, r = n - 1;
int pos = -1;
while(l <= r) {
int mid = l + r >> 1;
if(it.get(u, mid) >= v){
l = mid + 1;
pos = mid;
}
else r = mid - 1;
}
if(pos!=-1)
ans += (pos - u + 1);
//cout << pos << " ";
l = 1, r = n - 1;pos = -1;
while(l <= r){
int mid = l + r >> 1;
if(it.get(mid, u) >= v){
r = mid - 1;
pos= mid;
}
else l = mid + 1;
}
if(pos!=-1)ans += (u - pos + 1);
/// cout << pos << endl;
if(ans ==0)ans = 1;
cout << ans << endl;
}
}
}
int main()
{
sonic;
int TEST = 1;
// cin >> TEST;
while(TEST--)
{
Read();
Solve();
}
}
# | 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... |