-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathg.cpp
More file actions
51 lines (48 loc) · 1.27 KB
/
g.cpp
File metadata and controls
51 lines (48 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <bits/stdc++.h>
#define endl '\n'
#define eat cin
#define moo cout
#define int long long
using namespace std;
int T, N, M, a[100000];
int32_t main(){
eat.tie(0) -> sync_with_stdio(0);
eat >> T;
while(T--){
eat >> N >> M;
set<int> active;
for(int i = 0; i < N; i++){
eat >> a[i];
}
reverse(a, a+N);
for(int i = 0; i < N; i++){
auto it = active.insert(i).first;
while(it != active.begin()){
it--;
if(a[*it] < a[i]) break;
it = active.erase(it);
if(it == active.begin()) break;
}
}
for(int i = 0; i < M; i++){
int k, d; eat >> k >> d;
k = N-k;
a[k] -= d;
auto nx = active.upper_bound(k);
if(nx != active.end()){
if(a[*nx] <= a[k]){
moo << active.size() << ' ';
continue;
}
}
auto it = active.insert(k).first;
while(it != active.begin()){
it--;
if(a[*it] < a[k]) break;
it = active.erase(it);
}
moo << active.size() << ' ';
}
moo << endl;
}
}