Submission #1052047

#TimeUsernameProblemLanguageResultExecution timeMemory
1052047crafticatFinancial Report (JOI21_financial)C++17
100 / 100
247 ms69720 KiB
#include <bits/stdc++.h> using namespace std; #include <bits/stdc++.h> #include <utility> using namespace std; using ll = long long; using pi = pair<int,int>; using pl = pair<ll,ll>; #define temp(T) template<class T> temp(T) using V = vector<T>; using vi = V<int>; using vl = V<ll>; using vvi = V<vi>; using vpi = V<pi>; using vb = V<bool>; using vvb = V<vb>; vi dx = {0,1,-1,0}; vi dy = {1,0,0,-1}; #define sz(x) x.size() #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define rev(x) reverse(all(x)) #define sor(x) sort(all(x)) #define rsz resize #define ins insert #define pb push_back #define eb emplace_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define rep(a) F0R(_,a) #define each(a,x) for (auto& a: x) using str = string; const int MOD = 1e9 + 7; const ll BIG = 1e18; const int INF = 1e9 + 2; temp(T) bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } // set a = min(a,b) temp(T) bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } // set a = max(a,b) void unsyncIO() { cin.tie(0)->sync_with_stdio(0); } // FILE I/O void setIn(str s) { freopen(s.c_str(),"r",stdin); } void setOut(str s) { freopen(s.c_str(),"w",stdout); } void setIO(str s = "") { unsyncIO(); if (sz(s)) setIn(s+".in"), setOut(s+".out"); // for USACO } #define read(x) int x; cin >> x temp(T) void pr(T x) { cout << to_string(x); } temp(T) void prln(T x) { cout << to_string(x) << "\n"; } vi readV(int n) { vi input(n); F0R(i,n) cin >> input[i]; return input; } int rand(int a, int b) { return a + rand() % (b - a + 1); } #define gen(x,a,b) int x = rand(a,b) using tup = tuple<int, int, int>; temp(T) void moveAll(V<T> &a, V<T> &b) { each(x,b) { a.pb(x); } b.clear(); } vi genArr(int n, int a, int b) { vi generated(n); F0R(i,n) { generated[i] = rand(a,b); } return generated; } vvi genTree(int n) { vvi g(n + 1); F0R(i,n) { gen(p,0,i); g[p].pb(i + 1); g[i + 1].pb(p); } return g; } vvb readGrid(int a, int b) { vvb grid(a + 2, vb(b + 2, true)); F0R(i, a) { F0R(j, b) { bool k; cin >> k; grid[i + 1][j + 1] = k; } } return grid; } set<tup> s1; // Follow number by K, T set<tup> s2; // Follow T, by number, K void insert(int num, int k, int t) { s1.ins({num, k, t}); s2.ins({t, num, k}); } void erase(int num, int k, int t) { s1.erase({num, k, t}); s2.erase({t, num, k}); } struct Seg { Seg *left = nullptr, *right = nullptr; int l, r, mid; int v; Seg(int l, int r, vi &def) : l(l) ,r(r), mid((r + l) / 2) { if (r -l > 1) { left = new Seg(l,mid,def); right = new Seg(mid,r,def); v = min(left->v, right->v); } else { v = def[l]; } } int q(int a, int b) { if (b <= l || a >= r) return INF; if (a <= l && b >= r) { return v; } return min(left->q(a,b), right->q(a,b)); } }; int main() { setIO(); int n, d; cin >> n >> d; vi arr(n); F0R(i, n) { int k; cin >> k; arr[i] = k; } rev(arr); Seg seg(0, n, arr); int ans = 0; F0R(i, n) { auto z = s1.begin(); int mi = seg.q(i - d, i); while (!s1.empty() && get<0>(*z) < mi) { auto [a,b,c] = *z; erase(a,b,c); z = s1.begin(); } auto x = s1.lb({arr[i],-1, -1}); int k; if (x == s1.end()) { k = 1; insert(arr[i], k, i); } else { k = get<1>(*x) + (get<0>(*x) == arr[i] ? 0 : 1); insert(arr[i], k, i); } auto y = s1.lb({arr[i],k,i - 1}); while (y != s1.begin()) { y--; if (get<1>(*y) <= k) { auto [ad,bd,cd] = *y; erase(ad,bd,cd); } else break; y = s1.lb({arr[i],k,i - 1}); } ckmax(ans, get<1>(*s1.begin())); } cout << ans; return 0; }

Compilation message (stderr)

Main.cpp: In function 'void setIn(str)':
Main.cpp:60:28: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 | void setIn(str s) { freopen(s.c_str(),"r",stdin); }
      |                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'void setOut(str)':
Main.cpp:61:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 | void setOut(str s) { freopen(s.c_str(),"w",stdout); }
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...