이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define MAXN 100013
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
int N, M, Q;
pair<pii, int> edge[MAXN], quer[MAXN];
vector<array<int, 3> > events;
int seg[3 * MAXN];
void update(int w, int L, int R, int a, int t)
{
if (L == R)
{
seg[w] = t;
return;
}
int mid = (L + R) >> 1;
if (a <= mid)
{
update(w << 1, L, mid, a, t);
}
else
{
update(w << 1 | 1, mid + 1, R, a, t);
}
seg[w] = min(seg[w << 1], seg[w << 1 | 1]);
}
int query(int w, int L, int R, int a, int b)
{
if (a <= L && R <= b)
{
return seg[w];
}
int mid = (L + R) >> 1, res = 69;
if (a <= mid)
{
ckmin(res, query(w << 1, L, mid, a, b));
}
if (mid < b)
{
ckmin(res, query(w << 1 | 1, mid + 1, R, a, b));
}
return res;
}
//add an edge? resolve a query?
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(12);
cerr << fixed << setprecision(4);
cin >> N >> M;
FOR(i, 0, M)
{
int u, v, d;
cin >> u >> v >> d;
if (u > v) swap(u, v);
u--; v--;
edge[i] = {{u, v}, d};
update(1, 0, N - 1, u, d);
}
cin >> Q;
FOR(i, 0, Q)
{
cin >> quer[i].se >> quer[i].fi.fi >> quer[i].fi.se;
quer[i].fi.fi--;
if (quer[i].se == 1)
{
update(1, 0, N - 1, edge[quer[i].fi.fi].fi.fi, quer[i].fi.se);
}
else
{
int idx = quer[i].fi.fi, val = quer[i].fi.se;
int lt, rt;
int lo = 0, hi = idx;
while(hi > lo)
{
int mid = (hi + lo) >> 1;
if (query(1, 0, N - 1, mid, idx - 1) < val) lo = mid + 1;
else hi = mid;
}
lt = lo;
lo = idx; hi = N - 1;
while(hi > lo)
{
int mid = (hi + lo + 1) >> 1;
if (query(1, 0, N - 1, idx, mid - 1) < val) hi = mid - 1;
else lo = mid;
}
rt = lo;
cout << rt - lt + 1 << '\n';
}
}
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... |