이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define se second
#define fi first
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"
const int N = 5e5 + 9 , mod = 1e9 + 7;
ll a[N] , b[N] , dp[N] ,p[N] , sz[N] , c[N] , d[N] , ans[N] , t[N];
vector<pair<int,int>>v[N];
ll get(int x){
return (p[x] == x ? x : get(p[x]));
}
void join(int x , int y){
x = get(x) , y = get(y);
if(x != y){
if(sz[x] < sz[y])
swap(x , y);
p[y] = x;
sz[x] += sz[y];
}
}
bool bmp(int i , int j){
return c[i] > c[j];
}
struct query{
ll x , y , k;
}Q[N];
bool bmp1(query &i , query &j){
return i.y > j.y;
}
void pushup(int i){
t[i] = min(t[2 * i] , t[2 * i + 1]);
}
void add(int i , int l , int r , int tl , int tr , ll x){
int m = (l + r) / 2;
if(l > tr || r < tl) return;
if(l >= tl && r <= tr){
t[i] = x;
}else {
add(2 * i , l , m , tl , tr , x);
add(2 * i + 1 , m + 1 , r , tl , tr , x);
pushup(i);
}
}
ll get(int i , int l , int r , int tl , int tr){
int m = (l + r) / 2;
if(l > tr || r < tl) return 1e18;
if(l >= tl && r <= tr){
return t[i];
}else {
return min(get(2 * i , l , m , tl , tr) , get(2 * i + 1 , m + 1 , r , tl , tr));
}
}
void solve()
{
ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
cin>>n>>m;
for(i = 1; i <= m; i++){
cin>>a[i]>>b[i]>>c[i];
v[a[i]].pb({b[i] , c[i]});
v[b[i]].pb({a[i] , c[i]});
s += (min(a[i] , b[i]) != i || max(b[i] , a[i]) != i + 1);
d[i] = i;
}
cin>>q;
s = (s == 0 && m == n - 1);
if(s)
for(i = 1; i <= m; i++)
add(1 , 1 , m , i , i , c[i]);
vector<pair<int,int>>vc;
for(j = 1; j <= q; j++){
cin>>k>>x>>y;
if(s){
if(k == 1){
c[x] = y;
add(1 , 1 , m , x , x , c[x]);
}else {
ll L = x, R= x;
if(c[x - 1] >= y && x != 1){
r = x - 1;
l = 1;
while(l != r){
ll M = (l + r) / 2;
if(get(1 , 1 , m , M , x - 1) >= y)
r = M;
else
l = M + 1;
}
L = l;
}
if(x <= m && c[x] >= y){
l = x;
r = m;
while(l != r){
ll M = (l + r + 1) / 2;
if(get(1 , 1 , m , x , M) >= y)
l = M;
else
r = M - 1;
}
R = l + 1;
}
cout<<R - L + 1<<"\n";
}
if(j == q)
return;
continue;
}
Q[j] = {x , y , j};
if(max(n , m) <= 1000 && q <= 10000){
if(k == 1){
c[x] = y;
}else {
for(i = 1; i <= n; i++)
p[i] = i , sz[i] = 1;
for(i = 1; i <= m; i++){
if(c[i] >= y){
join(a[i] , b[i]);
}
}
cout<<sz[get(x)]<<"\n";
}
if(j == q)
return;
}
}
sort(d + 1 , d + m + 1 , bmp);
sort(Q + 1 , Q + q + 1 , bmp1);
for(i = 1; i <= n; i++)
p[i] = i , sz[i] = 1;
l = 1;
for(i = 1; i <= m + 1; i++){
j = d[i];
while(l <= q && Q[l].y > c[j]){
ans[Q[l].k] = sz[get(Q[l].x)];
l++;
}
join(a[j] , b[j]);
if(i == m + 1)
continue;
}
for(j = 1; j <= q; j++)
cout<<ans[j]<<"\n";
}
int main(){
TL;
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
int t = 1;
// cin>>t;
while(t--)
{
solve();
}
}
// Author : حسن
컴파일 시 표준 에러 (stderr) 메시지
bridges.cpp: In function 'void solve()':
bridges.cpp:78:46: warning: unused variable 'f' [-Wunused-variable]
78 | ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
| ^
bridges.cpp:78:58: warning: unused variable 'mx' [-Wunused-variable]
78 | ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
| ^~
bridges.cpp:78:67: warning: unused variable 'mn' [-Wunused-variable]
78 | ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
| ^~
# | 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... |