Codeforces Round #797 (Div. 3) G (STL乱搞)
https://codeforces.com/contest/1690/problem/G
思路:
- 车厢划分: 1 - s1-1, s1 - s2-1, ... sn-1 - n. 其中si是si-1左边第一个比他小的数
- 我们只保留s, 每次修改看修改过的数是被左边覆盖还是覆盖右边
- 观察jangly代码我么可以发现,用map可以简单的实现
https://codeforces.com/contest/1690/submission/159754104
#include<bits/stdc++.h>
//#include <bits/extc++.h>
using namespace std;
// using namespace __gnu_cxx;
// using namespace __gnu_pbds;
#define IOS ios::sync_with_stdio(false) ,cin.tie(0), cout.tie(0);
//#pragma GCC optimize(3,"Ofast","inline")
#define ll long long
#define ull unsigned long long
#define li __int128_t
#define PII pair<int, int>
#define re register
//#define int long long
const int N = 2e5 + 5;
const int M = 1e6 + 5;
const int mod = 1e9 + 7;
const ll LNF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
int a[N]; map<int, int> mp;
void add ( int i, int x ) {
mp[i] = x;
auto it = mp.find(i);
if( it != mp.begin() && prev(it) -> second <= x ) { mp.erase(it); return; }
while( next(it) != mp.end() && next(it) -> second >= x ) mp.erase(next(it));
}
void solve() {
mp.clear();
int n, m ; cin >> n >> m;
for ( int i = 1; i <= n; ++ i ) cin >> a[i];
for ( int i = 1; i <= n; ++ i ) add( i, a[i] );
while( m -- ) {
int pos, val; cin >> pos >> val;
add( pos, a[pos] -= val);
cout << mp.size() << " \n"[m == 0];
}
}
int main() {
IOS
int t; cin >> t;
while( t --) solve();
return 0;
}