Submission #1294822

#TimeUsernameProblemLanguageResultExecution timeMemory
1294822shidou26Employment (JOI16_employment)C++20
100 / 100
245 ms10892 KiB
#include <bits/stdc++.h> using namespace std; #ifdef KURUMI #include "algo/debug.h" #endif #define endl '\n' #define fi first #define se second #define sz(v) (int)v.size() #define all(v) v.begin(), v.end() #define filter(v) v.resize(unique(all(v)) - v.begin()) #define dbg(x) "[" #x << " = " << x << "]" mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); template<typename T1, typename T2> T2 rand(T1 l, T2 r) { return uniform_int_distribution<T2>(l, r)(rng); } template<typename T1, typename T2> T2 wrand(T1 l, T2 r, int seed) { if(seed == 0) return rand(l, r); else return (seed > 0 ? max(rand(l, r), wrand(l, r, seed - 1)) : min(rand(l, r), wrand(l, r, seed + 1))); } template<typename S, typename T> bool maximize(S &a, T b) { if(a < b) { a = b; return true; }else return false; } template<typename S, typename T> bool minimize(S &a, T b) { if(a > b) { a = b; return true; }else return false; } typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; typedef tuple<int, int, int> tp3; const int N = 2e5 + 3; int n, q; int a[N]; void input() { cin >> n >> q; for(int i = 1; i <= n; i++) { cin >> a[i]; } } int tmp[N]; vector<int> cps; int compress(int v) { return lower_bound(all(cps), v) - cps.begin() + 1; } struct FenwickTree { vector<int> tr; FenwickTree (int n) : tr(n + 3) {} void update(int p, int v) { for(; p > 0; p -= p & -p) tr[p] += v; } int get(int p) { int tot = 0; for(; p < sz(tr); p += p & -p) tot += tr[p]; return tot; } }; void process() { for(int i = 1; i <= n; i++) tmp[i] = a[i]; for(int i = 1; i < n; i++) { cps.push_back(min(a[i + 1], a[i])); cps.push_back(a[i]); } cps.push_back(a[n]); vector<pii> query; for(int i = 1; i <= q; i++) { int type; cin >> type; if(type == 1) { int b; cin >> b; query.emplace_back(-1, b); cps.push_back(b); }else { int p, v; cin >> p >> v; query.emplace_back(p, v); tmp[p] = v; cps.push_back(v); if(p > 1) cps.push_back(min(tmp[p], tmp[p - 1])); if(p < n) cps.push_back(min(tmp[p], tmp[p + 1])); } } sort(all(cps)); filter(cps); FenwickTree ft(sz(cps)), cnt(sz(cps)); for(int i = 1; i < n; i++) { ft.update(compress(min(a[i], a[i + 1])), 1); cnt.update(compress(a[i]), 1); } cnt.update(compress(a[n]), 1); for(pii it : query) { if(it.fi == -1) { int b = it.se; cout << cnt.get(compress(b)) - ft.get(compress(b)) << endl; } else { int p, v; tie(p, v) = it; if(p > 1) { ft.update(compress(min(a[p], a[p - 1])), -1); ft.update(compress(min(v, a[p - 1])), 1); } if(p < n) { ft.update(compress(min(a[p], a[p + 1])), -1); ft.update(compress(min(v, a[p + 1])), 1); } cnt.update(compress(a[p]), -1); cnt.update(compress(v), 1); a[p] = v; } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); #define task "TUYENDUNG" if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int testcase = 1; // cin >> testcase; for(int i = 1; i <= testcase; i++) { input(); process(); } cerr << "Saa, watashtachi no deeto hajimemashou" << endl; cerr << "Atarashii kiseki wo koko kara hajimeru shining place nee mou ichido kimi to..." << endl; return 0; }

Compilation message (stderr)

employment.cpp: In function 'int main()':
employment.cpp:147:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  147 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
employment.cpp:148:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  148 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...