이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//UNSTOPPABLE
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define int long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define pii pair<int,int>
#define sigma signed
#define tpii pair <pair <int,int> , int>
#define bruh cout << "NO\n"
using namespace std;
using namespace __gnu_pbds;
const int N = 3e5 + 5;
int mod = 1e9 + 7;
const int INF = 1e18;
int n,m,q,t[4 * N],used[N],x,cnt,w[N],u[N],v[N];
vector <int> g[N];
map <pii , multiset <int>> st;
void upd(int pos , int x , int v = 1 , int tl = 1 , int tr = n){
if(tl > pos || tr < pos) return;
if(tl == pos && tr == pos){
t[v] = x;
return;
}
int tm = tl + tr >> 1;
upd(pos , x , v * 2 , tl , tm);
upd(pos , x , v * 2 + 1 , tm + 1 , tr);
t[v] = min(t[v * 2] , t[v * 2 + 1]);
}
int get(int l , int r , int v = 1 , int tl = 1 , int tr = n){
if(tl > r || tr < l) return INF;
if(tl >= l && tr <= r) return t[v];
int tm = tl + tr >> 1;
return min(get(l , r , v * 2 , tl , tm) , get(l , r , v * 2 + 1 , tm + 1 , tr));
}
void dfs(int v , int p = 0){
used[v] = 1;
cnt++;
for(auto to : g[v]){
if(!used[to]){
if(*st[{v , to}].rbegin() >= x){
dfs(to , v);
}
}
}
}
void Goldik(){
cin >> n >> m;
for(int i = 1 ; i <= m ; i++){
cin >> u[i] >> v[i] >> w[i];
g[u[i]].pb(v[i]);
g[v[i]].pb(u[i]);
upd(u[i] , w[i]);
st[{u[i] , v[i]}].insert(w[i]);
st[{v[i] , u[i]}].insert(w[i]);
}
cin >> q;
if(n <= 1000 && m <= 1000 && q <= 10000){
for(int i = 1 ; i <= q ; i++){
int tp,qu,qv;
cin >> tp >> qu >> qv;
if(tp == 1){
st[{u[qu] , v[qu]}].erase(st[{u[qu] , v[qu]}].find(w[qu]));
st[{v[qu] , u[qu]}].erase(st[{v[qu] , u[qu]}].find(w[qu]));
w[qu] = qv;
st[{u[qu] , v[qu]}].insert(w[qu]);
st[{v[qu] , u[qu]}].insert(w[qu]);
}
else{
cnt = 0;
x = qv;
for(int i = 1 ; i <= n ; i++) used[i] = 0;
dfs(qu);
cout << cnt << '\n';
}
}
return;
}
for(int i = 1 ; i <= q ; i++){
int tp,u,v;
cin >> tp >> u >> v;
if(tp == 1){
upd(u , v);
}
else{
int l = 1 , r = u - 1 , res = u;
while(l <= r){
int md = l + r >> 1;
if(get(md , u - 1) < v){
l = md + 1;
}
else{
res = md;
r = md - 1;
}
}
l = u + 1 , r = n ; int res1 = u;
while(l <= r){
int md = l + r >> 1;
if(get(u , md - 1) < v){
r = md - 1;
}
else{
res1 = md;
l = md + 1;
}
}
cout << res1 - res + 1 << '\n';
}
}
}
//rewai mnogo zadach vozmozhno odna iz nih gde to popadetsya
//returning winter prime?
//chem prowe tem luchshe
sigma main(/*AZ AZDAN UZDIKSIZ*/){
//freopen("txt.in","r",stdin);
//freopen("txt.out","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
srand(time(0));
int TT = 1;
// cin >> TT;
for(int i = 1 ; i <= TT ; i++){
//cout << "Case " << i << ": ";
Goldik();
}
}
컴파일 시 표준 에러 (stderr) 메시지
bridges.cpp: In function 'void upd(long long int, long long int, long long int, long long int, long long int)':
bridges.cpp:31:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
31 | int tm = tl + tr >> 1;
| ~~~^~~~
bridges.cpp: In function 'long long int get(long long int, long long int, long long int, long long int, long long int)':
bridges.cpp:39:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
39 | int tm = tl + tr >> 1;
| ~~~^~~~
bridges.cpp: In function 'void Goldik()':
bridges.cpp:94:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
94 | int md = l + r >> 1;
| ~~^~~
bridges.cpp:105:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
105 | int md = l + r >> 1;
| ~~^~~
# | 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... |