Submission #14365126
Source Code Expand
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
#define def inf
template<class V, int NV> struct SegTree { //[l,r)
V comp(V& l, V& r) { return min(l, r); };
vector<V> val; SegTree() { val = vector<V>(NV * 2, def); }
V get(int x, int y, int l = 0, int r = NV, int k = 1) {
if (r <= x || y <= l)return def; if (x <= l && r <= y)return val[k];
auto a = get(x, y, l, (l + r) / 2, k * 2);
auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
return comp(a, b);
}
void update(int i, V v) {
i += NV; val[i] = v;
while (i > 1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
}
void add(int i, V v) { update(i, val[i + NV] + v); }
V operator[](int x) { return get(x, x + 1); }
};
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i @hamayanhamayan0
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int N, Q, A[201010], B[201010];
SegTree<int, 1 << 18> st;
multiset<int> rates[201010];
int cnt[201010];
//---------------------------------------------------------------------------------------------------
void add(int child, int to) {
cnt[to]++;
rates[to].insert(A[child]);
st.update(to, *rates[to].rbegin());
}
void erase(int child, int from) {
cnt[from]--;
auto ite = rates[from].find(A[child]);
rates[from].erase(ite);
if (cnt[from] == 0) st.update(from, inf);
else st.update(from, *rates[from].rbegin());
}
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> N >> Q;
rep(i, 1, N + 1) {
cin >> A[i] >> B[i];
add(i, B[i]);
}
rep(_, 0, Q) {
int C, D; cin >> C >> D;
erase(C, B[C]);
B[C] = D;
add(C, B[C]);
int ans = st.get(0, 201010);
printf("%d\n", ans);
}
}
Submission Info
Submission Time
2020-06-14 23:43:14+0900
Task
E - Smart Infants
User
hamayanhamayan
Language
C++ (GCC 9.2.1)
Score
500
Code Size
2996 Byte
Status
AC
Exec Time
468 ms
Memory
26368 KiB
Compile Error
./Main.cpp: In member function ‘V SegTree<V, NV>::get(int, int, int, int, int)’:
./Main.cpp:18:9: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
18 | if (r <= x || y <= l)return def; if (x <= l && r <= y)return val[k];
| ^~
./Main.cpp:18:42: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
18 | if (r <= x || y <= l)return def; if (x <= l && r <= y)return val[k];
| ^~
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
500 / 500
Status
AC
Set Name
Test Cases
Sample
All
handmade02, handmade03, handmade04, handmade05, handmade06, handmade07, handmade08, handmade09, random10, sample00, sample01
Case Name
Status
Exec Time
Memory
handmade02
AC
16 ms
14580 KiB
handmade03
AC
12 ms
15396 KiB
handmade04
AC
13 ms
15436 KiB
handmade05
AC
100 ms
14660 KiB
handmade06
AC
468 ms
25460 KiB
handmade07
AC
467 ms
25456 KiB
handmade08
AC
216 ms
26368 KiB
handmade09
AC
216 ms
26276 KiB
random10
AC
312 ms
26272 KiB
sample00
AC
17 ms
14656 KiB
sample01
AC
14 ms
14600 KiB