제출 #445573

#제출 시각아이디문제언어결과실행 시간메모리
445573hgmhcEmployment (JOI16_employment)C++17
30 / 100
137 ms10808 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...