이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define REP(i,a,b) for (auto i = (a); i <= (b); ++i)
#define PER(i,a,b) for (auto i = (b); i >= (a); --i)
#define log2(x) (31-__builtin_clz(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SZ(x) (int)(x).size()
#define PB push_back
#define FI first
#define SE second
#define mup(x,y) x = min(x,y)
#define Mup(x,y) x = max(x,y)
#define debug(x) cout << #x << " is " << x << el
#define el '\n'
using namespace std; using ll = long long; using ii = pair<int,int>; using iii = tuple<int,int,int>;
void solution(); int main() {ios::sync_with_stdio(0); cin.tie(0); solution();}
const int N = 200003;
int n, q, a[N], ans[N], cnt;
vector<ii> query, ord;
bool live[N];
void input() {
cin >> n >> q;
REP(i,1,n) {cin >> a[i]; ord.push_back({a[i],i});}
}
void solution() {
input();
REP(i,1,q) {
int x; cin >> x;
if (x&1) {
int b; cin >> b;
query.push_back({b,i});
}
else return;
}
sort(RALL(query));
sort(ALL(ord));
REP(i,0,q-1) {
auto [b,j] = query[i];
while (!ord.empty() && ord.back().first >= b) {
int idx = ord.back().second; ord.pop_back();
live[idx] = true; if (!live[idx-1] && !live[idx+1]) ++cnt;
if (live[idx-1] && live[idx+1]) --cnt;
}
ans[j] = cnt;
}
REP(i,1,q) cout << ans[i] << el;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |