#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
using namespace std;
using ll = long long;
const int N = 1e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 , mod = 1e9+7 , P = 6547;
int h[N] , u[N] , ans[N] , pos[N] , val[N] , type[N] , prank[N];
int K = 200;
struct node{
int l ,r , pix;
}t[4*N];
int n , q;
void upd(int pos , int val = 1 , int u = 1, int ul = 1, int ur = n) {
if(ul == ur) {
t[u].l = val;
t[u].r = val;
return;
}
int um = ul+ur >> 1;
if(pos <= um) {
upd(pos , val , u<<1 , ul , um);
}
else {
upd(pos , val , u<<1|1 , um+1 , ur);
}
t[u].l = t[u<<1].l;
t[u].r = t[u<<1|1].r;
t[u].pix = t[u<<1].pix + t[u<<1|1].pix + (t[u<<1].r != t[u<<1|1].l);
}
void solve() {
cin >> n >> q;
for(int i = 1; i <= n; i ++) {
cin >> h[i];
}
for(int i = 0; i <= q; i ++) {
if((i%K == 0 && i != 0) || i == q) {
vector<pair<int,int>> cons;
for(int i = 1; i <= n; i ++) {
if(u[i] == 0) {
cons.push_back({h[i] , i});
}
u[i] = 0;
}
sort(all(cons));
reverse(all(cons));
vector<pair<int,int>> ques;
vector<int> changes;
for(int j = max(i-K , 0); j < i; j ++) {
if(type[j] == 1) {
changes.push_back(j);
}
else {
ques.push_back({val[j] , j});
}
}
// cout << "QUES\n";
sort(all(ques));
for(auto x: changes) {
prank[x] = h[pos[x]];
}
set<int> st;
for(auto to: ques) {
while(cons.size() && cons.back().F < to.F) {
st.insert(cons.back().S);
upd(cons.back().S);
cons.pop_back();
}
for(auto x: changes) {
if(x > to.S) break;
h[pos[x]] = val[x];
}
for(auto x: changes) {
if(h[pos[x]] < to.F) {
upd(pos[x]);
st.insert(cons.back().S);
}
}
ans[to.S] = t[1].pix;
for(auto x: changes) {
upd(pos[x] , 0);
h[pos[x]] = prank[x];
}
}
for(auto x: changes) {
h[pos[x]] = val[x];
}
for(auto to: st) {
upd(to , 0);
}
}
if(i == q) break;
cin >> type[i];
if(type[i] == 1) {
cin >> pos[i] >> val[i];
u[pos[i]] = 1;
}
else {
cin >> val[i];
}
}
for(int i = 0; i < q; i ++) {
if(type[i] == 2)
cout << ans[i] << '\n';
}
}
/*
*/
main() {
ios;
int tt = 1;
// cin >> tt;
while(tt --) {
solve();
}
return 0;
}
Compilation message
game.cpp: In function 'void upd(int, int, int, int, int)':
game.cpp:30:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
30 | int um = ul+ur >> 1;
| ~~^~~
game.cpp: At global scope:
game.cpp:125:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
125 | main() {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
12 ms |
492 KB |
Output is correct |
3 |
Correct |
12 ms |
492 KB |
Output is correct |
4 |
Correct |
12 ms |
492 KB |
Output is correct |
5 |
Correct |
12 ms |
492 KB |
Output is correct |
6 |
Correct |
12 ms |
492 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
12 ms |
492 KB |
Output is correct |
3 |
Correct |
12 ms |
492 KB |
Output is correct |
4 |
Correct |
12 ms |
492 KB |
Output is correct |
5 |
Correct |
12 ms |
492 KB |
Output is correct |
6 |
Correct |
12 ms |
492 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Execution timed out |
1083 ms |
10144 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
12 ms |
492 KB |
Output is correct |
3 |
Correct |
12 ms |
492 KB |
Output is correct |
4 |
Correct |
12 ms |
492 KB |
Output is correct |
5 |
Correct |
12 ms |
492 KB |
Output is correct |
6 |
Correct |
12 ms |
492 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Execution timed out |
1083 ms |
10144 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |